CheckpointSkinItem.ts 2.3 KB

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