widget_item.ts 30 KB

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