widget_item.ts 28 KB

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