widget_item.ts 29 KB

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