widget_item.ts 33 KB

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