CheckpointLevelItem.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Color, Label, Sprite, SpriteFrame, _decorator, CCInteger } from "cc";
  2. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  3. import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
  4. import { SingletonModuleComp } from "../../common/SingletonModuleComp";
  5. import FlashSprite from "../../../../../extensions/oops-plugin-framework/assets/libs/animator-effect/2d/FlashSprite";
  6. import { VehicleType } from "../../vehicle/model/VehicleEnum";
  7. const { ccclass, property } = _decorator;
  8. /** 等级显示Item界面 */
  9. @ccclass('CheckpointLevelItemViewComp')
  10. @ecs.register('CheckpointLevelItemView', false)
  11. export class CheckpointLevelItemViewComp extends CCComp {
  12. @property({ type: CCInteger, visible: true, tooltip: '当前关卡' })
  13. lv: number = 0
  14. private img_doubt
  15. private img_air
  16. private img_bus
  17. private img_car
  18. private img_lock
  19. private img_pass
  20. private img_line
  21. private label_level
  22. onAdded(args: any) {
  23. console.log(args);
  24. }
  25. onLoad() {
  26. this.img_air = this.node.getChildByPath("aircraft")
  27. this.img_bus = this.node.getChildByPath("Bus")
  28. this.img_car = this.node.getChildByPath("convertible")
  29. this.img_doubt = this.node.getChildByPath("doubt")
  30. this.img_lock = this.node.getChildByPath("Progressnotunlocked")
  31. this.img_pass = this.node.getChildByPath("Progressilluminated")
  32. this.img_line = this.node.getChildByPath("SpriteSplash")
  33. this.label_level = this.node.getChildByPath("level")
  34. }
  35. initView() {
  36. this.hideVechicle()
  37. this.img_pass.active = false
  38. this.img_doubt.active = false
  39. this.setTextLv()
  40. }
  41. setTextLv() {
  42. this.label_level.getComponent(Label).string = `${this.lv ? this.lv : ''}`
  43. }
  44. protected lateUpdate(dt: number): void {
  45. if (this.lv === 0) {
  46. this.initView()
  47. return
  48. }
  49. this.hideVechicle()
  50. this.setTextLv()
  51. const curLv = ecs.getSingleton(SingletonModuleComp).account.AccountModel.lv
  52. if (curLv >= this.lv) {
  53. this.img_pass.active = true
  54. this.img_lock.active = false
  55. this.changeProgressStatu(true)
  56. } else {
  57. this.img_pass.active = false
  58. this.img_lock.active = true
  59. this.changeProgressStatu(false)
  60. if (this.lv === curLv + 1) {
  61. const type = ecs.getSingleton(SingletonModuleComp).account.checkpoint.CheckpointModelLevel.rtluNext.vehicleType
  62. this.showVechicle(type)
  63. this.img_doubt.active = false
  64. } else {
  65. this.img_doubt.active = true
  66. }
  67. }
  68. }
  69. hideVechicle() {
  70. this.img_air.active = false
  71. this.img_car.active = false
  72. this.img_bus.active = false
  73. this.img_doubt.active = false
  74. }
  75. showVechicle(t: VehicleType) {
  76. this.hideVechicle()
  77. switch (t) {
  78. case VehicleType.CAR:
  79. this.img_car.active = true
  80. break;
  81. case VehicleType.BUS:
  82. this.img_bus.active = true
  83. break;
  84. case VehicleType.AIRPLANT:
  85. this.img_air.active = true
  86. break;
  87. default:
  88. this.img_doubt.active = false
  89. break;
  90. }
  91. }
  92. changeProgressStatu(v: boolean) {
  93. this.img_line.getComponent(Sprite).color = v ? new Color('#00B6F8') : new Color('#646464')
  94. }
  95. reset() {
  96. this.node.destroy();
  97. }
  98. }