widget_item.ts 30 KB

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