FunUnlock.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, Component, Sprite, sp, Animation, Vec3, Node, Label } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { OpenWindow } from '../core/ui/window/OpenWindow';
  4. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  5. import { WindowSystem } from '../core/ui/window/WindowSystem';
  6. import { UserData } from '../data/UserData';
  7. const { ccclass, property } = _decorator;
  8. /*功能解锁 */
  9. @ccclass('FunUnlock')
  10. export class FunUnlock extends Component {
  11. @property({ type: Sprite, tooltip: "按扭" }) iconBg: Sprite = null;
  12. @property({ type: Sprite, tooltip: "锁图片" }) lockSprite: Sprite;
  13. @property({ type: Sprite, tooltip: "按扭图片" }) lockIconSprite: Sprite;
  14. @property({ type: Animation, tooltip: "按扭图片" }) iconAni: Animation = null;
  15. @property({ type: sp.Skeleton, tooltip: "未开启图片" }) spine: sp.Skeleton = null;
  16. @property({ type: OpenWindow, tooltip: "系统对应窗口" }) openWin: OpenWindow;
  17. @property({ type: Node, tooltip: "红点节点" }) redPointNode: Node;
  18. @property({ tooltip: "解锁条件" }) unLockKey: string = "lv";
  19. @property({ tooltip: "解锁关卡等级" }) openLv = 1;
  20. private isOpen = false;
  21. start() {
  22. this.setFunUnlock();
  23. }
  24. update() {
  25. !this.isOpen && DataSystem.watch(UserData, this.unLockKey) && this.setFunUnlock();
  26. }
  27. private setFunUnlock() {
  28. let lv = DataSystem.getData(UserData)[this.unLockKey];
  29. if (lv >= this.openLv) {
  30. this.isOpen = true;
  31. this.lockSprite.node.active = false;
  32. this.lockIconSprite.grayscale = false;
  33. this.redPointNode && (this.redPointNode.active = true);
  34. this.iconBg && (this.iconBg.grayscale = false);
  35. this.iconAni && this.iconAni.play();
  36. if (this.spine) {
  37. this.lockIconSprite.node.active = false;
  38. this.spine.node.setScale(new Vec3(0.15, 0.15, 1));
  39. }
  40. } else {
  41. this.lockSprite.node.active = true;
  42. this.redPointNode && (this.redPointNode.active = false);
  43. this.lockIconSprite.grayscale = true;
  44. this.redPointNode && (this.redPointNode.active = false);
  45. if (this.iconBg) {
  46. this.iconBg.node.active = true;
  47. this.iconBg.grayscale = true;
  48. }
  49. }
  50. }
  51. private onOpen() {
  52. if (this.isOpen) {
  53. this.openWin.openMode = WindowOpenMode.CloseAndCover;
  54. this.openWin.open();
  55. } else {
  56. WindowSystem.showTips((this.unLockKey == 'lv' ? '关卡' : '兵营') + '达到' + this.openLv + '级开启');
  57. }
  58. }
  59. }