widget_item.ts 31 KB

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