widget_item.ts 32 KB

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