widget_item.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. })
  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. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  323. if(this.x_len==0){
  324. this.x_len = (et.getUILocation().x - pos.x)*2;
  325. this.y_len = (et.getUILocation().y - pos.y)*2;
  326. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  327. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  328. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  329. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  330. }
  331. // console.log("this.x_len",this.x_len,this.y_len)
  332. this.isMove = true;
  333. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  334. })
  335. this.node.on(Node.EventType.MOUSE_LEAVE,()=>{
  336. if(this.node.parent.name=="content"){
  337. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  338. }
  339. this.isMove = false;
  340. this.x_len = 0;
  341. this.y_len = 0;
  342. })
  343. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  344. if(this.node.parent.name=="content"){
  345. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  346. }
  347. this.isMove = false;
  348. this.x_len = 0;
  349. this.y_len = 0;
  350. // MAC电脑浏览器
  351. if(config.is_MAC_edit) {
  352. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  353. if(this.x_len==0){
  354. this.x_len = (et.getUILocation().x - pos.x)*2;
  355. this.y_len = (et.getUILocation().y - pos.y)*2;
  356. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  357. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  358. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  359. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  360. }
  361. // console.log("this.x_len",this.x_len,this.y_len)
  362. this.isMove = true;
  363. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  364. }
  365. })
  366. }
  367. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  368. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  369. }
  370. protected onDestroy(): void {
  371. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  372. }
  373. UpdateAttributesToView(data:attributes_data,update_type:string){
  374. if(this.m_att===null){
  375. return;
  376. }
  377. if(data.id===this.m_att.id){
  378. console.log("this.m_att",this.m_att)
  379. switch(update_type){
  380. case config.attributes_list_type.pos:
  381. this.m_att.x = data.x;
  382. this.m_att.y = data.y;
  383. this.m_att.z = data.z;
  384. this.node.setSiblingIndex(this.m_att.z)
  385. this.node.position = new Vec3(data.x,data.y)
  386. break;
  387. case config.attributes_list_type.animation:
  388. this.m_att.animation_list = data.animation_list;
  389. break;
  390. case config.attributes_list_type.size:
  391. this.m_att.width = data.width;
  392. this.m_att.height = data.height;
  393. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  394. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  395. break;
  396. case config.attributes_list_type.anchor:
  397. this.m_att.anchor_x = data.anchor_x;
  398. this.m_att.anchor_y = data.anchor_y;
  399. this.spr.getComponent(UITransform).setAnchorPoint(data.anchor_x, data.anchor_y)
  400. break;
  401. case config.attributes_list_type.rotation:
  402. this.m_att.rotation = data.rotation;
  403. this.spr.angle = data.rotation;
  404. break;
  405. case config.attributes_list_type.url:
  406. this.m_att.src = data.src
  407. this.m_att.src_name = data.src_name
  408. if(this.m_att.src.length<=0){
  409. this.spr.getComponent(Sprite).spriteFrame = null
  410. }else{
  411. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  412. if (!err && imageAsset2) {
  413. this.lab_name.active = false;
  414. const texture = new Texture2D();
  415. texture.image = imageAsset2;
  416. let spFrame2 = new SpriteFrame();
  417. spFrame2.texture = texture;
  418. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  419. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  420. director.once(Director.EVENT_AFTER_DRAW,()=>{
  421. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  422. })
  423. }
  424. });
  425. }
  426. break;
  427. case config.attributes_list_type.origin:
  428. if(this.m_att.src.length>0){
  429. this.spr.getComponent(UITransform).setContentSize(new Size(this.m_att.width,this.m_att.height))
  430. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  431. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  432. // this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
  433. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  434. // console.log("Director.EVENT_AFTER_DRAW")
  435. // this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  436. // this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  437. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  438. // this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  439. // })
  440. // ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  441. // })
  442. }
  443. break;
  444. case config.attributes_list_type.delete:
  445. this.node.destroy()
  446. this.node.removeFromParent()
  447. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
  448. ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
  449. break;
  450. case config.attributes_list_type.drag:
  451. this.m_att.drag_data = data.drag_data
  452. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  453. this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
  454. this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
  455. if(this.m_att.drag_data.other_drag_list==undefined){
  456. this.m_att.drag_data.other_drag_list = []
  457. }
  458. // 更新 其他拖拽
  459. this.other_drag_content.removeAllChildren()
  460. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  461. const element = this.m_att.drag_data.other_drag_list[index];
  462. let item = instantiate(this.drag)
  463. item.off(Node.EventType.TOUCH_MOVE)
  464. item.parent = this.other_drag_content;
  465. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  466. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  467. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  468. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  469. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  470. item.position = n_p;
  471. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  472. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  473. })
  474. item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
  475. item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
  476. item.active = element.is_show_inTheEditor
  477. }
  478. }
  479. break;
  480. case config.attributes_list_type.drag_err_back_status:
  481. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  482. this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
  483. }
  484. break;
  485. case config.attributes_list_type.slide:
  486. if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  487. this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
  488. this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
  489. this.m_att.slide_data.slide_num = data.slide_data.slide_num;
  490. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  491. }
  492. break;
  493. case config.attributes_list_type.click:
  494. if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  495. this.m_att.click_data = data.click_data;
  496. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
  497. }
  498. case config.attributes_list_type.is_interaction:
  499. this.m_att.is_interaction = data.is_interaction;
  500. break;
  501. case config.attributes_list_type.find_widget_pos:
  502. this.Shiny()
  503. break;
  504. case config.attributes_list_type.active:
  505. this.m_att.edit_active = data.edit_active;
  506. this.node.active = this.m_att.edit_active
  507. this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
  508. break;
  509. case config.attributes_list_type.top:
  510. this.m_att.top_data = data.top_data;
  511. if(this.m_ui_widget!=null){
  512. this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
  513. }
  514. break;
  515. case config.attributes_list_type.text_sound:
  516. this.m_att.text_sound_data = data.text_sound_data;
  517. if(this.m_text_sound!=null){
  518. this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
  519. }
  520. break;
  521. case config.attributes_list_type.question_select:
  522. this.m_att.question_select = data.question_select;
  523. if(this.m_question_select!=null){
  524. this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
  525. }
  526. break;
  527. case config.attributes_list_type.count_down:
  528. this.m_att.count_down = data.count_down;
  529. if(this.m_count_down!=null){
  530. this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
  531. }
  532. break;
  533. case config.attributes_list_type.zIndex:
  534. this.m_att.zIndex = data.zIndex;
  535. break;
  536. case config.attributes_list_type.dir:
  537. this.m_att.img_dir = data.img_dir;
  538. this.updateDir()
  539. break;
  540. case config.attributes_list_type.show:
  541. this.m_att.is_show = data.is_show;
  542. break;
  543. case config.attributes_list_type.container:
  544. this.m_att.container_layer = data.container_layer
  545. // this.initConatiner()
  546. break;
  547. }
  548. }
  549. director.once(Director.EVENT_AFTER_DRAW,()=>{
  550. ClientEvent.dispatchEvent(config.Event.updateWidgetData)
  551. })
  552. }
  553. updateDir(){
  554. if(this.call_back==null){
  555. switch (this.m_att.img_dir) {
  556. case config.widget_scale_dir.left:
  557. this.spr.scale = new Vec3(-1,1)
  558. break;
  559. case config.widget_scale_dir.up:
  560. this.spr.scale = new Vec3(1,-1)
  561. break;
  562. case config.widget_scale_dir.normal:
  563. this.spr.scale = new Vec3(1,1)
  564. break;
  565. }
  566. }
  567. }
  568. getOtherDragListColor(index:number):Color {
  569. var color_index = index
  570. if(index >= config.COLOR_LIST.length) {
  571. let count = Math.floor(index / config.COLOR_LIST.length)
  572. color_index = index - (config.COLOR_LIST.length * count)
  573. }
  574. return config.COLOR_LIST[color_index]
  575. // return Color.YELLOW
  576. }
  577. Shiny(){
  578. this.img_select.active = true;
  579. this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  580. Tween.stopAllByTarget(this.img_select)
  581. tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
  582. this.img_select.active = false;
  583. }).start()
  584. }
  585. public getWidgetAtt(){
  586. this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
  587. this.m_att.remark = this.m_att.remark;
  588. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  589. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  590. this.m_att.anchor_x = this.m_att.anchor_x==undefined?0.5:this.m_att.anchor_x
  591. this.m_att.anchor_y = this.m_att.anchor_y==undefined?0.5:this.m_att.anchor_y
  592. this.m_att.rotation = this.m_att.rotation;
  593. this.m_att.x = this.node.position.x;
  594. this.m_att.widget_type = this.m_data.type;
  595. this.m_att.y = this.node.position.y;
  596. this.m_att.z = this.node.getSiblingIndex();
  597. this.m_att.type = config.attributes_type.widget;
  598. this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
  599. if(this.m_att.drag_data!=null){
  600. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  601. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  602. this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
  603. this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
  604. }
  605. return this.m_att;
  606. }
  607. initWidgetAtt(){
  608. if(this.call_back==null){
  609. this.node.position = new Vec3(this.m_att.x,this.m_att.y)
  610. this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
  611. this.spr.angle = this.m_att.rotation
  612. this.spr.getComponent(UITransform).setAnchorPoint(new Vec2(this.m_att.anchor_x, this.m_att.anchor_y))
  613. if(this.m_att.drag_data!=null){
  614. this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
  615. this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
  616. }
  617. this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  618. this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
  619. }else{
  620. this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
  621. }
  622. if(this.m_att.src!=""&&this.m_att.src.length>0){
  623. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  624. if (!err && imageAsset2) {
  625. const texture = new Texture2D();
  626. texture.image = imageAsset2;
  627. let spFrame2 = new SpriteFrame();
  628. spFrame2.texture = texture;
  629. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  630. }
  631. });
  632. }
  633. //进行数据差矫正
  634. let t_data = new attributes_data
  635. for (const key in t_data) {
  636. if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
  637. const element = t_data[key];
  638. if(this.m_att[key]===undefined){
  639. this.m_att[key] = element;
  640. }
  641. }
  642. }
  643. this.updateDir()
  644. }
  645. public getData(){
  646. if(this.m_att!=null){
  647. this.getWidgetAtt()
  648. }
  649. this.m_data.att = this.m_att;
  650. return this.m_data;
  651. }
  652. public setData(data){
  653. this.m_data = data;
  654. }
  655. public getContainer(){
  656. return this.container
  657. }
  658. }