CheckpointSkinItem.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { _decorator, EventTouch, Label, Node, 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 { SkinChangeComp } from "../bll/SkinChange";
  6. import { DataSdk, REPORT_EVENT } from "../../common/utils/datasdk";
  7. const { ccclass, property } = _decorator;
  8. /** 皮肤Item界面 */
  9. @ccclass('CheckpointSkinItemViewComp')
  10. @ecs.register('CheckpointSkinItemView', false)
  11. export class CheckpointSkinItemViewComp extends CCComp {
  12. @property({ type: CCInteger, visible: true, tooltip: '当前关卡' })
  13. id: number = 1
  14. private btn_change_skin
  15. private label_lock
  16. private img_inuse
  17. private img_lock
  18. onAdded(args: any) {
  19. console.log(args);
  20. }
  21. onLoad() {
  22. this.btn_change_skin = this.node.getChildByPath("Replacement")
  23. this.label_lock = this.node.getChildByPath("label_lock")
  24. this.img_lock = this.node.getChildByPath("lock")
  25. this.img_inuse = this.node.getChildByPath("inuse")
  26. this.label_lock.getComponent(Label).string = `关卡${this.id}解锁`
  27. this.btn_change_skin.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  28. }
  29. private onTouchEnd(event: EventTouch) {
  30. const comp = ecs.getSingleton(SingletonModuleComp).account.checkpoint.add(SkinChangeComp)
  31. comp.skinId = this.id
  32. event.propagationStopped = true;
  33. DataSdk.reportEvent(REPORT_EVENT.CLICK_CHANGE_SKIN,ecs.getSingleton(SingletonModuleComp)?.account?.AccountModel?.lv)
  34. }
  35. protected lateUpdate(dt: number): void {
  36. const accountModel = ecs.getSingleton(SingletonModuleComp).account.AccountModel
  37. if (accountModel.lv >= this.id || (accountModel.reward && this.id === 3)) { // 抖音栏侧奖励皮肤
  38. this.img_lock.active = false
  39. this.label_lock.active = false
  40. if (accountModel.skin == this.id) {
  41. this.btn_change_skin.active = false
  42. this.img_inuse.active = true
  43. } else {
  44. this.btn_change_skin.active = true
  45. this.img_inuse.active = false
  46. }
  47. } else {
  48. this.img_lock.active = true
  49. this.btn_change_skin.active = false
  50. this.img_inuse.active = false
  51. this.label_lock.active = true
  52. }
  53. }
  54. reset() {
  55. this.node.destroy();
  56. }
  57. }