car_info.ts 5.5 KB

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