results_new_car.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { _decorator, Component, Director, director, instantiate, Label, Node, Prefab, ScrollView, Sprite } from 'cc';
  2. import { base_ui } from '../fw/base_ui';
  3. import { user_results } from '../data';
  4. import { dataManager } from '../manager/dataManager';
  5. import { tools } from '../tools';
  6. import { results_item } from './results_item';
  7. import { userDataManager } from '../manager/userDataManager';
  8. import { uiManager } from '../manager/uiManager';
  9. import { config } from '../config';
  10. import { ClientEvent } from '../lib/clientEvent';
  11. import { http } from '../http';
  12. import { car_lib } from '../ui/car_lib/car_lib';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('results_new_car')
  15. export class results_new_car extends base_ui {
  16. @property(Node) btn_sure:Node = null
  17. @property(Node) btn_go_lib:Node = null
  18. @property(Node) btn_use_car:Node = null
  19. @property(Node) content:Node = null
  20. @property(Node) lab_fen:Node = null
  21. @property(Node) lab_name:Node = null
  22. @property(Node) icon_car:Node = null
  23. @property(Prefab) item_pf:Prefab = null
  24. @property(Node) layout_car_list:Node = null
  25. private default_car_id:number = -1
  26. // @property(Node) layout_btns:Node = null
  27. protected start(): void {
  28. this.onButtonListen(this.btn_sure,this.close.bind(this))
  29. this.onButtonListen(this.btn_go_lib,()=>{
  30. uiManager.Instance().showUi(config.UI.car_lib, this.node, (n:Node)=>{
  31. n.getComponent(car_lib).initGameShowStatus(this.node)
  32. })
  33. })
  34. this.onButtonListen(this.btn_use_car,()=>{
  35. if(this.default_car_id!=-1){
  36. userDataManager.user_car_list.default_car_id = this.default_car_id
  37. ClientEvent.dispatchEvent(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR)
  38. this.syncUserSetDefaultCar()
  39. }
  40. this.default_car_id = -1
  41. this.close()
  42. })
  43. }
  44. private syncUserSetDefaultCar() {
  45. let opt = {'car_id': userDataManager.user_car_list.default_car_id}
  46. http.post(config.API.user_set_default_car_id, opt, (err,d)=>{
  47. let nd = JSON.parse(d)
  48. if(nd.code === config.status.SUCCESS){}
  49. })
  50. }
  51. protected close(): void {
  52. this.node.active = false
  53. }
  54. public show(fen:number,data:user_results){
  55. if(data.obtain_list.length<=0){
  56. return
  57. }
  58. this.node.active = true
  59. this.btn_sure.active = true
  60. this.content.removeAllChildren()
  61. let new_car_d = dataManager.getUserCarInfo(data.obtain_list[0])
  62. if(data.obtain_list.length>1){
  63. this.layout_car_list.active = true
  64. for (let index = 1; index < data.obtain_list.length; index++) {
  65. let d = data.obtain_list[index];
  66. let item = instantiate(this.item_pf)
  67. item.parent = this.content
  68. item.getComponent(results_item).init(dataManager.getUserCarInfo(d))
  69. }
  70. this.btn_go_lib.active = true
  71. this.btn_use_car.active = false
  72. // director.once(Director.EVENT_AFTER_DRAW,()=>{
  73. // this.content.parent.parent.getComponent(ScrollView).scrollToLeft(0.1)
  74. // })
  75. }else{
  76. this.default_car_id = new_car_d.id
  77. this.btn_go_lib.active = false
  78. this.btn_use_car.active = true
  79. this.layout_car_list.active = false
  80. }
  81. tools.loadRemoteImg(new_car_d.background_cover,(data)=>{
  82. this.icon_car.getComponent(Sprite).spriteFrame = data.sf
  83. })
  84. this.lab_fen.getComponent(Label).string = `${fen} 分`
  85. this.lab_name.getComponent(Label).string = new_car_d.name
  86. }
  87. }