widget_item.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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.anchor:
  350. this.m_att.anchor_x = data.anchor_x;
  351. this.m_att.anchor_y = data.anchor_y;
  352. this.spr.getComponent(UITransform).setAnchorPoint(data.anchor_x, data.anchor_y)
  353. break;
  354. case config.attributes_list_type.rotation:
  355. this.m_att.rotation = data.rotation;
  356. this.spr.angle = data.rotation;
  357. break;
  358. case config.attributes_list_type.url:
  359. this.m_att.src = data.src
  360. this.m_att.src_name = data.src_name
  361. if(this.m_att.src.length<=0){
  362. this.spr.getComponent(Sprite).spriteFrame = null
  363. }else{
  364. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  365. if (!err && imageAsset2) {
  366. this.lab_name.active = false;
  367. const texture = new Texture2D();
  368. texture.image = imageAsset2;
  369. let spFrame2 = new SpriteFrame();
  370. spFrame2.texture = texture;
  371. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  372. this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
  373. director.once(Director.EVENT_AFTER_DRAW,()=>{
  374. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  375. })
  376. }
  377. });
  378. }
  379. break;
  380. case config.attributes_list_type.origin:
  381. if(this.m_att.src.length>0){
  382. this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
  383. director.once(Director.EVENT_AFTER_DRAW,()=>{
  384. console.log("Director.EVENT_AFTER_DRAW")
  385. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  386. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  387. director.once(Director.EVENT_AFTER_DRAW,()=>{
  388. this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
  389. })
  390. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
  391. })
  392. }
  393. break;
  394. case config.attributes_list_type.delete:
  395. this.node.destroy()
  396. this.node.removeFromParent()
  397. ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
  398. ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
  399. break;
  400. case config.attributes_list_type.drag:
  401. this.m_att.drag_data = data.drag_data
  402. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  403. this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
  404. this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
  405. if(this.m_att.drag_data.other_drag_list==undefined){
  406. this.m_att.drag_data.other_drag_list = []
  407. }
  408. this.other_drag_content.removeAllChildren()
  409. for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
  410. const element = this.m_att.drag_data.other_drag_list[index];
  411. let item = instantiate(this.drag)
  412. item.off(Node.EventType.TOUCH_MOVE)
  413. item.parent = this.other_drag_content;
  414. item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
  415. item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
  416. item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  417. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  418. let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
  419. item.position = n_p;
  420. this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
  421. this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
  422. })
  423. item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
  424. item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
  425. item.active = element.is_show_inTheEditor
  426. }
  427. }
  428. break;
  429. case config.attributes_list_type.drag_err_back_status:
  430. if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
  431. this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
  432. }
  433. break;
  434. case config.attributes_list_type.slide:
  435. if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
  436. this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
  437. this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
  438. this.m_att.slide_data.slide_num = data.slide_data.slide_num;
  439. this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
  440. }
  441. break;
  442. case config.attributes_list_type.click:
  443. if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
  444. this.m_att.click_data = data.click_data;
  445. this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
  446. }
  447. case config.attributes_list_type.is_interaction:
  448. this.m_att.is_interaction = data.is_interaction;
  449. break;
  450. case config.attributes_list_type.find_widget_pos:
  451. this.Shiny()
  452. break;
  453. case config.attributes_list_type.active:
  454. this.m_att.edit_active = data.edit_active;
  455. this.node.active = this.m_att.edit_active
  456. this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
  457. break;
  458. case config.attributes_list_type.top:
  459. this.m_att.top_data = data.top_data;
  460. if(this.m_ui_widget!=null){
  461. this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
  462. }
  463. break;
  464. case config.attributes_list_type.text_sound:
  465. this.m_att.text_sound_data = data.text_sound_data;
  466. if(this.m_text_sound!=null){
  467. this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
  468. }
  469. break;
  470. case config.attributes_list_type.question_select:
  471. this.m_att.question_select = data.question_select;
  472. if(this.m_question_select!=null){
  473. this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
  474. }
  475. break;
  476. case config.attributes_list_type.count_down:
  477. this.m_att.count_down = data.count_down;
  478. if(this.m_count_down!=null){
  479. this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
  480. }
  481. break;
  482. case config.attributes_list_type.zIndex:
  483. this.m_att.zIndex = data.zIndex;
  484. break;
  485. case config.attributes_list_type.dir:
  486. this.m_att.img_dir = data.img_dir;
  487. this.updateDir()
  488. break;
  489. case config.attributes_list_type.show:
  490. this.m_att.is_show = data.is_show;
  491. break;
  492. }
  493. }
  494. director.once(Director.EVENT_AFTER_DRAW,()=>{
  495. ClientEvent.dispatchEvent(config.Event.updateWidgetData)
  496. })
  497. }
  498. updateDir(){
  499. if(this.call_back==null){
  500. switch (this.m_att.img_dir) {
  501. case config.widget_scale_dir.left:
  502. this.spr.scale = new Vec3(-1,1)
  503. break;
  504. case config.widget_scale_dir.up:
  505. this.spr.scale = new Vec3(1,-1)
  506. break;
  507. case config.widget_scale_dir.normal:
  508. this.spr.scale = new Vec3(1,1)
  509. break;
  510. }
  511. }
  512. }
  513. getOtherDragListColor(index:number):Color {
  514. var color_index = index
  515. if(index >= config.COLOR_LIST.length) {
  516. let count = Math.floor(index / config.COLOR_LIST.length)
  517. color_index = index - (config.COLOR_LIST.length * count)
  518. }
  519. return config.COLOR_LIST[color_index]
  520. // return Color.YELLOW
  521. }
  522. Shiny(){
  523. this.img_select.active = true;
  524. this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  525. Tween.stopAllByTarget(this.img_select)
  526. tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
  527. this.img_select.active = false;
  528. }).start()
  529. }
  530. public getWidgetAtt(){
  531. this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
  532. this.m_att.remark = this.m_att.remark;
  533. this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
  534. this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
  535. this.m_att.anchor_x = this.m_data.att.anchor_x
  536. this.m_att.anchor_y = this.m_data.att.anchor_y
  537. this.m_att.rotation = this.m_att.rotation;
  538. this.m_att.x = this.node.position.x;
  539. this.m_att.widget_type = this.m_data.type;
  540. this.m_att.y = this.node.position.y;
  541. this.m_att.z = this.node.getSiblingIndex();
  542. this.m_att.type = config.attributes_type.widget;
  543. this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
  544. if(this.m_att.drag_data!=null){
  545. this.m_att.drag_data.drag_pos_x = this.drag.position.x;
  546. this.m_att.drag_data.drag_pos_y = this.drag.position.y;
  547. this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
  548. this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
  549. }
  550. return this.m_att;
  551. }
  552. initWidgetAtt(){
  553. if(this.call_back==null){
  554. this.node.position = new Vec3(this.m_att.x,this.m_att.y)
  555. this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
  556. this.spr.angle = this.m_att.rotation
  557. if(this.m_att.drag_data!=null){
  558. this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
  559. this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
  560. }
  561. this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
  562. this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
  563. }else{
  564. this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
  565. }
  566. if(this.m_att.src!=""&&this.m_att.src.length>0){
  567. assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
  568. if (!err && imageAsset2) {
  569. const texture = new Texture2D();
  570. texture.image = imageAsset2;
  571. let spFrame2 = new SpriteFrame();
  572. spFrame2.texture = texture;
  573. this.spr.getComponent(Sprite).spriteFrame = spFrame2
  574. }
  575. });
  576. }
  577. //进行数据差矫正
  578. let t_data = new attributes_data
  579. for (const key in t_data) {
  580. if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
  581. const element = t_data[key];
  582. if(this.m_att[key]===undefined){
  583. this.m_att[key] = element;
  584. }
  585. }
  586. }
  587. this.updateDir()
  588. }
  589. public getData(){
  590. if(this.m_att!=null){
  591. this.getWidgetAtt()
  592. }
  593. this.m_data.att = this.m_att;
  594. return this.m_data;
  595. }
  596. public setData(data){
  597. this.m_data = data;
  598. }
  599. }