ui_base.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { _decorator, Component, Node, Size, Sprite, UITransform } from 'cc';
  2. import { att_top_data, event_item, ui_att_item, widget_item_data } from '../../../data/data';
  3. import { tools } from '../../tools';
  4. import { gameManager } from '../gameManager';
  5. import { ClientEvent } from '../../clientEvent';
  6. import { config } from '../../config';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('ui_base')
  9. export class ui_base extends Component {
  10. @property(Node) btn_close:Node = null;
  11. @property(Node) btn_jump:Node = null;
  12. @property(Node) bg:Node = null;
  13. protected mData:widget_item_data = null;
  14. protected mTopData:att_top_data = null;
  15. protected mIsFinish:boolean = false;
  16. protected initWidget(data:widget_item_data){
  17. this.mData = data;
  18. this.node.active = false;
  19. this.mTopData = this.mData.att.top_data;
  20. if(this.mTopData===null){
  21. tools.showToast("初始化ui错误")
  22. return;
  23. }
  24. if(this.mTopData.is_open_close){
  25. this.btn_close.active = true;
  26. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  27. this.close()
  28. })
  29. this.node.on(Node.EventType.TOUCH_START,()=>{
  30. this.close()
  31. })
  32. gameManager.initUiBaseAtt(this.btn_close,this.mTopData.close_info)
  33. }else{
  34. this.btn_close.active = false;
  35. }
  36. if(this.mTopData.is_open_jump){
  37. this.btn_jump.active = true;
  38. gameManager.initUiBaseAtt(this.btn_jump,this.mTopData.jump_info)
  39. }else{
  40. this.btn_jump.active = false;
  41. }
  42. this.init()
  43. ClientEvent.on(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
  44. };
  45. protected onDestroy(): void {
  46. ClientEvent.off(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
  47. }
  48. beActive(widgetId:number,event:event_item){
  49. if(widgetId===this.mData.att.id){
  50. if(event.type==config.event_type.active_event){
  51. this.show()
  52. }
  53. }
  54. }
  55. close(){
  56. this.hide()
  57. this.onCloseEvent()
  58. }
  59. public show(){
  60. console.log("fuck!")
  61. this.node.active = true;
  62. this.onShow()
  63. }
  64. protected onShow(){
  65. }
  66. public hide(){
  67. this.node.active = false;
  68. }
  69. protected loadBg(bgInfo:ui_att_item){
  70. if(bgInfo.res_name.length>0){
  71. gameManager.initUiBaseAtt(this.bg,bgInfo)
  72. }
  73. }
  74. protected onCloseEvent(){
  75. if(this.mTopData.close_event_id!=-1){
  76. ClientEvent.dispatchEvent(config.EventRun.TOP_VIEW_CLOSE,this.mTopData.close_event_id)
  77. }
  78. }
  79. protected onFinishEvent(){
  80. this.mIsFinish = true;
  81. this.hide()
  82. console.log("his.mTopData.finish_event_id",this.mTopData.finish_event_id)
  83. if(this.mTopData.finish_event_id!=-1){
  84. ClientEvent.dispatchEvent(config.EventRun.TOP_VIEW_FINISH,this.mTopData.finish_event_id)
  85. }
  86. }; //完成自身
  87. protected onFialEvent(){
  88. this.hide()
  89. if(this.mTopData.fail_event_id!=-1){
  90. ClientEvent.dispatchEvent(config.EventRun.TOP_VIEW_FAIL,this.mTopData.fail_event_id)
  91. }
  92. }; // 失败完成
  93. protected init(){};
  94. public initView(data:widget_item_data){
  95. this.initWidget(data)
  96. };
  97. }