widget_item.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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_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. initCountDown(){
  186. if(this.call_back==null){
  187. let _time_count = instantiate(this.count_down_pf)
  188. _time_count.parent = this.node;
  189. _time_count.getComponent(count_down).initView(this.m_att.count_down)
  190. this.m_count_down = _time_count;
  191. this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
  192. }
  193. }
  194. initWidgetHaveAtt(att:attributes_data){
  195. if(att!=null){
  196. this.lab_name.active = true;
  197. this.m_att = att;
  198. this.initWidgetAtt()
  199. }else{
  200. this.m_att = new attributes_data
  201. this.m_att.id = config.getNewId();
  202. }
  203. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  204. if(this.m_att.drag_data===null){
  205. this.m_att.drag_data = new att_drag_data;
  206. }
  207. this.drag.active = true;
  208. if(this.m_isShowDragOtherList == false) {
  209. this.initDrag()
  210. }
  211. }else if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  212. this.slide.active = true;
  213. if(this.m_att.slide_data===null){
  214. this.m_att.slide_data = new att_slide_data;
  215. }
  216. this.initSlide()
  217. }else if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  218. if(this.m_att.click_data===null){
  219. this.m_att.click_data = new att_click_data;
  220. }
  221. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type) +`id${this.m_att.id}`
  222. }else if(this.m_data.type===config.Widget_Type_List.UI_TOP){
  223. if(this.m_att.top_data===null){
  224. this.m_att.top_data = new att_top_data;
  225. }
  226. this.initUiWidget()
  227. 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}`
  228. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  229. if(this.m_att.text_sound_data===null){
  230. this.m_att.text_sound_data = new att_text_sound_data;
  231. }
  232. this.lab_name.getComponent(Label).string =`文本和语音-id:${this.m_att.id}`
  233. this.initTextSound()
  234. }else if(this.m_data.type===config.Widget_Type_List.QUESTION_SELECT){
  235. if(this.m_att.question_select===null){
  236. this.m_att.question_select = new att_question_select;
  237. }
  238. this.initQuestionSelect()
  239. this.lab_name.getComponent(Label).string =`问题选择-id:${this.m_att.id}`
  240. }else if(this.m_data.type===config.Widget_Type_List.COUNT_DOWN){
  241. if(this.m_att.count_down===null){
  242. this.m_att.count_down = new att_count_down;
  243. }
  244. this.initCountDown()
  245. this.lab_name.getComponent(Label).string =`倒计时-id:${this.m_att.id}`
  246. }
  247. this.node.active = this.m_att.edit_active
  248. }
  249. public initWidgetByScene(data:widget_item_data,att:attributes_data=null){
  250. this.m_data = data;
  251. this.initWidgetHaveAtt(att)
  252. if(this.m_data.type===config.Widget_Type_List.UI_TOP){ //弹窗不可以拖动
  253. // MAC电脑浏览器
  254. if(config.is_MAC_edit) {
  255. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  256. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  257. })
  258. return
  259. }
  260. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  261. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  262. })
  263. }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
  264. // MAC电脑浏览器
  265. if(config.is_MAC_edit) {
  266. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  267. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  268. })
  269. return
  270. }
  271. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  272. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  273. })
  274. }else{
  275. this.node.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  276. if(this.isMove){
  277. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  278. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  279. let offset_x = this.x_len;
  280. let offset_y = this.y_len;
  281. this.node.position = new Vec3(n_p.x-offset_x,n_p.y-offset_y);
  282. if(this.node.parent.name=="content"){
  283. this.node.parent.parent.parent.getComponent(scroll_scene).stopTouch()
  284. }
  285. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  286. }
  287. })
  288. this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
  289. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  290. if(this.x_len==0){
  291. this.x_len = (et.getUILocation().x - pos.x)*2;
  292. this.y_len = (et.getUILocation().y - pos.y)*2;
  293. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  294. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  295. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  296. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  297. }
  298. // console.log("this.x_len",this.x_len,this.y_len)
  299. this.isMove = true;
  300. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  301. })
  302. this.node.on(Node.EventType.MOUSE_LEAVE,()=>{
  303. if(this.node.parent.name=="content"){
  304. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  305. }
  306. this.isMove = false;
  307. this.x_len = 0;
  308. this.y_len = 0;
  309. })
  310. this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
  311. if(this.node.parent.name=="content"){
  312. this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
  313. }
  314. this.isMove = false;
  315. this.x_len = 0;
  316. this.y_len = 0;
  317. // MAC电脑浏览器
  318. if(config.is_MAC_edit) {
  319. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
  320. if(this.x_len==0){
  321. this.x_len = (et.getUILocation().x - pos.x)*2;
  322. this.y_len = (et.getUILocation().y - pos.y)*2;
  323. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  324. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  325. this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
  326. // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
  327. }
  328. // console.log("this.x_len",this.x_len,this.y_len)
  329. this.isMove = true;
  330. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  331. }
  332. })
  333. }
  334. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  335. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  336. }
  337. protected onDestroy(): void {
  338. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  339. }
  340. UpdateAttributesToView(data:attributes_data,update_type:string){
  341. if(this.m_att===null){
  342. return;
  343. }
  344. if(data.id===this.m_att.id){
  345. switch(update_type){
  346. case config.attributes_list_type.pos:
  347. this.m_att.x = data.x;
  348. this.m_att.y = data.y;
  349. this.m_att.z = data.z;
  350. this.node.setSiblingIndex(this.m_att.z)
  351. this.node.position = new Vec3(data.x,data.y)
  352. break;
  353. case config.attributes_list_type.animation:
  354. this.m_att.animation_list = data.animation_list;
  355. break;
  356. case config.attributes_list_type.size:
  357. this.m_att.width = data.width;
  358. this.m_att.height = data.height;
  359. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  360. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  361. break;
  362. case config.attributes_list_type.anchor:
  363. this.m_att.anchor_x = data.anchor_x;
  364. this.m_att.anchor_y = data.anchor_y;
  365. this.spr.getComponent(UITransform).setAnchorPoint(data.anchor_x, data.anchor_y)
  366. break;
  367. case config.attributes_list_type.rotation:
  368. this.m_att.rotation = data.rotation;
  369. this.spr.angle = data.rotation;
  370. break;
  371. case config.attributes_list_type.url:
  372. this.m_att.src = data.src
  373. this.m_att.src_name = data.src_name
  374. if(this.m_att.src.length<=0){
  375. this.spr.getComponent(Sprite).spriteFrame = null
  376. }else{
  377. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  378. if (!err && imageAsset2) {
  379. this.lab_name.active = false;
  380. const texture = new Texture2D();
  381. texture.image = imageAsset2;
  382. let spFrame2 = new SpriteFrame();
  383. spFrame2.texture = texture;
  384. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  385. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  386. director.once(Director.EVENT_AFTER_DRAW,()=>{
  387. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  388. })
  389. }
  390. });
  391. }
  392. break;
  393. case config.attributes_list_type.origin:
  394. if(this.m_att.src.length>0){
  395. this.spr.getComponent(UITransform).setContentSize(new Size(this.m_att.width,this.m_att.height))
  396. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  397. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  398. // this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
  399. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  400. // console.log("Director.EVENT_AFTER_DRAW")
  401. // this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  402. // this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  403. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  404. // this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  405. // })
  406. // ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  407. // })
  408. }
  409. break;
  410. case config.attributes_list_type.delete:
  411. this.node.destroy()
  412. this.node.removeFromParent()
  413. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
  414. ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
  415. break;
  416. case config.attributes_list_type.drag:
  417. this.m_att.drag_data = data.drag_data
  418. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  419. this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
  420. this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
  421. if(this.m_att.drag_data.other_drag_list==undefined){
  422. this.m_att.drag_data.other_drag_list = []
  423. }
  424. // 更新 其他拖拽
  425. this.other_drag_content.removeAllChildren()
  426. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  427. const element = this.m_att.drag_data.other_drag_list[index];
  428. let item = instantiate(this.drag)
  429. item.off(Node.EventType.TOUCH_MOVE)
  430. item.parent = this.other_drag_content;
  431. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  432. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  433. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  434. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  435. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  436. item.position = n_p;
  437. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  438. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  439. })
  440. item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
  441. item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
  442. item.active = element.is_show_inTheEditor
  443. }
  444. }
  445. break;
  446. case config.attributes_list_type.drag_err_back_status:
  447. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  448. this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
  449. }
  450. break;
  451. case config.attributes_list_type.slide:
  452. if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  453. this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
  454. this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
  455. this.m_att.slide_data.slide_num = data.slide_data.slide_num;
  456. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  457. }
  458. break;
  459. case config.attributes_list_type.click:
  460. if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  461. this.m_att.click_data = data.click_data;
  462. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
  463. }
  464. case config.attributes_list_type.is_interaction:
  465. this.m_att.is_interaction = data.is_interaction;
  466. break;
  467. case config.attributes_list_type.find_widget_pos:
  468. this.Shiny()
  469. break;
  470. case config.attributes_list_type.active:
  471. this.m_att.edit_active = data.edit_active;
  472. this.node.active = this.m_att.edit_active
  473. this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
  474. break;
  475. case config.attributes_list_type.top:
  476. this.m_att.top_data = data.top_data;
  477. if(this.m_ui_widget!=null){
  478. this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
  479. }
  480. break;
  481. case config.attributes_list_type.text_sound:
  482. this.m_att.text_sound_data = data.text_sound_data;
  483. if(this.m_text_sound!=null){
  484. this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
  485. }
  486. break;
  487. case config.attributes_list_type.question_select:
  488. this.m_att.question_select = data.question_select;
  489. if(this.m_question_select!=null){
  490. this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
  491. }
  492. break;
  493. case config.attributes_list_type.count_down:
  494. this.m_att.count_down = data.count_down;
  495. if(this.m_count_down!=null){
  496. this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
  497. }
  498. break;
  499. case config.attributes_list_type.zIndex:
  500. this.m_att.zIndex = data.zIndex;
  501. break;
  502. case config.attributes_list_type.dir:
  503. this.m_att.img_dir = data.img_dir;
  504. this.updateDir()
  505. break;
  506. case config.attributes_list_type.show:
  507. this.m_att.is_show = data.is_show;
  508. break;
  509. }
  510. }
  511. director.once(Director.EVENT_AFTER_DRAW,()=>{
  512. ClientEvent.dispatchEvent(config.Event.updateWidgetData)
  513. })
  514. }
  515. updateDir(){
  516. if(this.call_back==null){
  517. switch (this.m_att.img_dir) {
  518. case config.widget_scale_dir.left:
  519. this.spr.scale = new Vec3(-1,1)
  520. break;
  521. case config.widget_scale_dir.up:
  522. this.spr.scale = new Vec3(1,-1)
  523. break;
  524. case config.widget_scale_dir.normal:
  525. this.spr.scale = new Vec3(1,1)
  526. break;
  527. }
  528. }
  529. }
  530. getOtherDragListColor(index:number):Color {
  531. var color_index = index
  532. if(index >= config.COLOR_LIST.length) {
  533. let count = Math.floor(index / config.COLOR_LIST.length)
  534. color_index = index - (config.COLOR_LIST.length * count)
  535. }
  536. return config.COLOR_LIST[color_index]
  537. // return Color.YELLOW
  538. }
  539. Shiny(){
  540. this.img_select.active = true;
  541. this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  542. Tween.stopAllByTarget(this.img_select)
  543. tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
  544. this.img_select.active = false;
  545. }).start()
  546. }
  547. public getWidgetAtt(){
  548. this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
  549. this.m_att.remark = this.m_att.remark;
  550. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  551. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  552. this.m_att.anchor_x = this.m_att.anchor_x==undefined?0.5:this.m_att.anchor_x
  553. this.m_att.anchor_y = this.m_att.anchor_y==undefined?0.5:this.m_att.anchor_y
  554. this.m_att.rotation = this.m_att.rotation;
  555. this.m_att.x = this.node.position.x;
  556. this.m_att.widget_type = this.m_data.type;
  557. this.m_att.y = this.node.position.y;
  558. this.m_att.z = this.node.getSiblingIndex();
  559. this.m_att.type = config.attributes_type.widget;
  560. this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
  561. if(this.m_att.drag_data!=null){
  562. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  563. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  564. this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
  565. this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
  566. }
  567. return this.m_att;
  568. }
  569. initWidgetAtt(){
  570. if(this.call_back==null){
  571. this.node.position = new Vec3(this.m_att.x,this.m_att.y)
  572. this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
  573. this.spr.angle = this.m_att.rotation
  574. this.spr.getComponent(UITransform).setAnchorPoint(new Vec2(this.m_att.anchor_x, this.m_att.anchor_y))
  575. if(this.m_att.drag_data!=null){
  576. this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
  577. this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
  578. }
  579. this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  580. this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
  581. }else{
  582. this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
  583. }
  584. if(this.m_att.src!=""&&this.m_att.src.length>0){
  585. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  586. if (!err && imageAsset2) {
  587. const texture = new Texture2D();
  588. texture.image = imageAsset2;
  589. let spFrame2 = new SpriteFrame();
  590. spFrame2.texture = texture;
  591. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  592. }
  593. });
  594. }
  595. //进行数据差矫正
  596. let t_data = new attributes_data
  597. for (const key in t_data) {
  598. if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
  599. const element = t_data[key];
  600. if(this.m_att[key]===undefined){
  601. this.m_att[key] = element;
  602. }
  603. }
  604. }
  605. this.updateDir()
  606. }
  607. public getData(){
  608. if(this.m_att!=null){
  609. this.getWidgetAtt()
  610. }
  611. this.m_data.att = this.m_att;
  612. return this.m_data;
  613. }
  614. public setData(data){
  615. this.m_data = data;
  616. }
  617. }