car_info.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { _decorator, Component, Label, Node, Sprite, UIOpacity } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { car_item_data, car_type } from '../../data';
  4. import { imageCacheManager } from '../../manager/imageCacheManager';
  5. import { userDataManager } from '../../manager/userDataManager';
  6. import { car_info_shuxing } from './car_info_shuxing';
  7. import { dataManager } from '../../manager/dataManager';
  8. import { car_info_get_suipian } from './car_info_get_suipian';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('car_info')
  11. export class car_info extends base_ui {
  12. @property(Node) public_bg:Node = null
  13. @property(Node) btn_close:Node = null
  14. @property(Node) lab_xiangcha_score:Node = null
  15. @property(Node) img_car:Node = null
  16. @property(Node) lab_car_name:Node = null
  17. @property(Node) lab_score:Node = null
  18. @property(Node) img_suo:Node = null
  19. @property(Node) shuxing_info:Node = null
  20. @property(Node) operate_btn_node:Node = null
  21. @property(Node) btn_zhuangbei:Node = null
  22. @property(Node) btn_duihuan:Node = null
  23. @property(Node) get_suipian_node:Node = null
  24. private m_data:car_item_data = null
  25. private m_is_jiesuo:boolean = false
  26. private m_zhuangbei_cb = null
  27. private m_duihuan_cb = null
  28. private m_look_video_cb = null
  29. private m_share_cb = null
  30. start() {
  31. this.onButtonListen(this.public_bg, ()=>{
  32. this.close()
  33. })
  34. this.onButtonListen(this.btn_close, ()=>{
  35. this.close()
  36. })
  37. this.onButtonListen(this.btn_zhuangbei, ()=>{
  38. this.close()
  39. this.m_zhuangbei_cb && this.m_zhuangbei_cb(this)
  40. })
  41. this.onButtonListen(this.btn_duihuan, ()=>{
  42. this.m_duihuan_cb && this.m_duihuan_cb(this)
  43. })
  44. this.get_suipian_node.getComponent(car_info_get_suipian).initView(()=>{
  45. this.m_look_video_cb && this.m_look_video_cb(this)
  46. }, ()=>{
  47. this.m_share_cb && this.m_share_cb(this)
  48. })
  49. this.setCarSuipianData()
  50. }
  51. public initView(data:car_item_data, is_jiesuo:boolean) {
  52. this.m_data = data
  53. this.m_is_jiesuo = is_jiesuo
  54. if(is_jiesuo) {
  55. this.img_suo.active = false
  56. this.lab_car_name.active = false
  57. this.lab_xiangcha_score.getComponent(Label).string = data.name
  58. this.lab_score.getComponent(Label).string = userDataManager.user_data.license_code
  59. } else {
  60. if(data.stype==car_type.score) {
  61. let xiangcha_score = data.unlock_points - userDataManager.user_car_list.max_integral
  62. if(xiangcha_score<0) {
  63. xiangcha_score = 0
  64. }
  65. this.lab_xiangcha_score.getComponent(Label).string = `距离解锁还差 ${xiangcha_score} 分`
  66. this.lab_score.getComponent(Label).string = data.unlock_points + '分解锁'
  67. } else {
  68. let cur_count = data.temp_bag_list_item_data.quantity
  69. let xiangcha_score = data.unlock_points - cur_count
  70. if(xiangcha_score<0) {
  71. xiangcha_score = 0
  72. }
  73. this.lab_xiangcha_score.getComponent(Label).string = `距离解锁还差 ${xiangcha_score} 碎片`
  74. this.lab_score.getComponent(Label).string = `已集齐 ${cur_count} / ${data.unlock_points}碎片`
  75. }
  76. this.img_suo.active = true
  77. this.lab_car_name.active = true
  78. this.lab_car_name.getComponent(Label).string = data.name
  79. }
  80. this.img_car.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.id)
  81. this.shuxing_info.getComponent(car_info_shuxing).initView(data)
  82. this.operate_btn_node.active = false
  83. this.get_suipian_node.active = false
  84. if(is_jiesuo) {
  85. this.showOperateNode(true)
  86. if(userDataManager.user_car_list.default_car_id==data.id) {
  87. this.btn_zhuangbei.active = false
  88. } else {
  89. this.btn_zhuangbei.active = true
  90. }
  91. this.btn_duihuan.active = false
  92. } else {
  93. if(data.stype==car_type.suipian) {
  94. if(dataManager.userCarListHavCar(data.id)) {
  95. this.showOperateNode(true)
  96. this.btn_zhuangbei.active = true
  97. this.btn_duihuan.active = false
  98. } else {
  99. let cur_count = data.temp_bag_list_item_data.quantity
  100. if(cur_count-data.unlock_points>=0) {
  101. this.showOperateNode(true)
  102. this.btn_zhuangbei.active = false
  103. this.btn_duihuan.active = true
  104. } else {
  105. // 看视频/分享 碎片
  106. this.showOperateNode(false)
  107. }
  108. }
  109. }
  110. }
  111. }
  112. public initOperateNodeCallback(zhuangbei_cb, duihuan_cb) {
  113. this.m_zhuangbei_cb = zhuangbei_cb
  114. this.m_duihuan_cb = duihuan_cb
  115. }
  116. public initGetSuipianNodeCallback(look_video_cb, share_cb) {
  117. this.m_look_video_cb = look_video_cb
  118. this.m_share_cb = share_cb
  119. }
  120. public setCarSuipianData() {
  121. this.get_suipian_node.getComponent(car_info_get_suipian).setData()
  122. }
  123. public closeSelf() {
  124. this.close()
  125. }
  126. public getData():car_item_data {
  127. return this.m_data
  128. }
  129. public getIsJiesuo():boolean {
  130. return this.m_is_jiesuo
  131. }
  132. private showOperateNode(is_show:boolean) {
  133. if(is_show) {
  134. this.operate_btn_node.active = true
  135. this.get_suipian_node.active = false
  136. } else {
  137. this.operate_btn_node.active = false
  138. this.get_suipian_node.active = true
  139. }
  140. }
  141. }