exchange_car_view.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Label, Node, Sprite } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { dataManager } from '../../manager/dataManager';
  4. import { tools } from '../../tools';
  5. import { exchange_car_success } from './exchange_car_success';
  6. import { http } from '../../http';
  7. import { config } from '../../config';
  8. import { GameManager } from '../../GameManager';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('exchange_car_view')
  11. export class exchange_car_view extends base_ui {
  12. @property(Node) bg_view:Node = null
  13. @property(Node) bg_public_bg:Node = null
  14. @property(Node) lab_name:Node = null
  15. @property(Node) img_car_bg:Node = null
  16. @property(Node) img_sp:Node = null
  17. @property(Node) img_car:Node = null
  18. @property(Node) lab_current_count:Node = null
  19. @property(Node) lab_total_count:Node = null
  20. @property(Node) btn_exchange:Node = null
  21. @property(Node) success_view:Node = null
  22. private m_car_id:number = 0
  23. private m_cb = null
  24. start() {
  25. this.onButtonListen(this.bg_public_bg, ()=>{
  26. this.close()
  27. })
  28. this.onButtonListen(this.btn_exchange, ()=>{
  29. this.requestExchangeCar()
  30. })
  31. }
  32. initView(data, cb) {
  33. this.m_cb = cb
  34. this.m_car_id = data.car_id
  35. let car_item = dataManager.getUserCarInfo(data.car_id)
  36. this.lab_name.getComponent(Label).string = car_item.name
  37. tools.loadRemoteImg(car_item.background_cover, (d)=>{
  38. this.img_car_bg.getComponent(Sprite).spriteFrame = d.sf
  39. })
  40. tools.loadRemoteImg(data.sp_icon, (d)=>{
  41. this.img_sp.getComponent(Sprite).spriteFrame = d.sf
  42. })
  43. this.img_car.getComponent(Sprite).spriteFrame = dataManager.getUserRankCarSf(car_item.id,-1)
  44. this.lab_current_count.getComponent(Label).string = `${data.sp_count}`
  45. this.lab_total_count.getComponent(Label).string = `/${car_item.unlock_points}`
  46. if(data.sp_count>=car_item.unlock_points) {
  47. this.btn_exchange.active = true
  48. } else {
  49. this.btn_exchange.active = false
  50. }
  51. }
  52. private requestExchangeCar() {
  53. GameManager.requestExchangeCar(this.m_car_id, ()=>{
  54. this.bg_view.active = false
  55. this.success_view.active = true
  56. this.success_view.getComponent(exchange_car_success).initView(this.m_car_id, ()=>{
  57. this.close()
  58. this.m_cb && this.m_cb()
  59. })
  60. },true)
  61. }
  62. }