SkinItem2.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, Color, Component, instantiate, Node, Prefab, Sprite, Vec2, Vec3 } from 'cc';
  2. import { SkinItem } from './SkinItem';
  3. import EventMgr from '../../script/Manager/EventMgr';
  4. import { Skin } from '../../script/Manager/LocalDataMgr';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('SkinItem2')
  7. export class SkinItem2 extends SkinItem {
  8. @property({type:Node})
  9. lock:Node = null
  10. @property({type:Node})
  11. usingLabel:Node = null
  12. @property(Sprite)
  13. bgSprite:Sprite = null
  14. @property({type:Node})
  15. btnUse:Node = null
  16. private unlockColor = "C16D51"
  17. private lockColor = "FFFFFF"
  18. private key:number = -1
  19. private isUnlock:boolean = false
  20. protected override start(): void {
  21. super.start()
  22. this.btnUse.on(Node.EventType.TOUCH_END,this.onBtnUseClick,this)
  23. }
  24. override init(key: number,spine:Prefab,animName:string = "idle",spineOffset:Vec2 = new Vec2(0,0),isUnlock:boolean = false)
  25. {
  26. let skin = instantiate(spine)
  27. this.skinRoot.addChild(skin)
  28. skin.active = true
  29. skin.setPosition(Vec3.ZERO)
  30. skin.position = skin.position.clone().add3f(spineOffset.x,spineOffset.y,0)
  31. this.lock.active = !isUnlock
  32. this.key = key
  33. this.setBgColor(isUnlock)
  34. this.isUnlock = isUnlock
  35. }
  36. override onClick()
  37. {
  38. this.isUnlock = true
  39. this.setBgColor(this.isUnlock)
  40. this.lock.active = !this.isUnlock
  41. Skin.addSelectSkin(this.key)
  42. }
  43. onBtnUseClick()
  44. {
  45. Skin.setSelectStatu(true)
  46. EventMgr.ins.dispatchEvent("showUsingLabel",[this.node,this.isUnlock])
  47. EventMgr.ins.dispatchEvent("regenerate")
  48. }
  49. setBgColor(isUnlock)
  50. {
  51. let color = new Color()
  52. this.bgSprite.color = isUnlock ? Color.fromHEX(color, this.unlockColor) : Color.fromHEX(color, this.lockColor);
  53. }
  54. }