import { _decorator, Component, Sprite, sp, Animation, Vec3, Node, Label } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { OpenWindow } from '../core/ui/window/OpenWindow'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { WindowSystem } from '../core/ui/window/WindowSystem'; import { UserData } from '../data/UserData'; const { ccclass, property } = _decorator; /*功能解锁 */ @ccclass('FunUnlock') export class FunUnlock extends Component { @property({ type: Sprite, tooltip: "按扭" }) iconBg: Sprite = null; @property({ type: Sprite, tooltip: "锁图片" }) lockSprite: Sprite; @property({ type: Sprite, tooltip: "按扭图片" }) lockIconSprite: Sprite; @property({ type: Animation, tooltip: "按扭图片" }) iconAni: Animation = null; @property({ type: sp.Skeleton, tooltip: "未开启图片" }) spine: sp.Skeleton = null; @property({ type: OpenWindow, tooltip: "系统对应窗口" }) openWin: OpenWindow; @property({ type: Node, tooltip: "红点节点" }) redPointNode: Node; @property({ tooltip: "解锁条件" }) unLockKey: string = "lv"; @property({ tooltip: "解锁关卡等级" }) openLv = 1; private isOpen = false; start() { this.setFunUnlock(); } update() { !this.isOpen && DataSystem.watch(UserData, this.unLockKey) && this.setFunUnlock(); } private setFunUnlock() { let lv = DataSystem.getData(UserData)[this.unLockKey]; if (lv >= this.openLv) { this.isOpen = true; this.lockSprite.node.active = false; this.lockIconSprite.grayscale = false; this.redPointNode && (this.redPointNode.active = true); this.iconBg && (this.iconBg.grayscale = false); this.iconAni && this.iconAni.play(); if (this.spine) { this.lockIconSprite.node.active = false; this.spine.node.setScale(new Vec3(0.15, 0.15, 1)); } } else { this.lockSprite.node.active = true; this.redPointNode && (this.redPointNode.active = false); this.lockIconSprite.grayscale = true; this.redPointNode && (this.redPointNode.active = false); if (this.iconBg) { this.iconBg.node.active = true; this.iconBg.grayscale = true; } } } private onOpen() { if (this.isOpen) { this.openWin.openMode = WindowOpenMode.CloseAndCover; this.openWin.open(); } else { WindowSystem.showTips((this.unLockKey == 'lv' ? '关卡' : '兵营') + '达到' + this.openLv + '级开启'); } } }