39 lines
2.4 KiB
TypeScript
39 lines
2.4 KiB
TypeScript
const { ccclass } = cc._decorator;
|
|
|
|
/** Plays the editable tutorial template; no runtime layout construction. */
|
|
@ccclass
|
|
export default class WeeklyGuide extends cc.Component {
|
|
private openedAt = 0;
|
|
private animated: cc.Node[] = [];
|
|
static show(parent: cc.Node, template: cc.Node, height: number, designHeight: number): void {
|
|
if (parent.getChildByName('weekly-guide')) return;
|
|
const node = cc.instantiate(template); node.name = 'weekly-guide'; node.active = true;
|
|
parent.addChild(node); node.zIndex = 100;
|
|
node.getComponent(WeeklyGuide).play(height, designHeight);
|
|
}
|
|
private appear(node: cc.Node, delay: number, duration = 0.42, startScale = 0.72): void {
|
|
const sx = node.scaleX, sy = node.scaleY, opacity = node.opacity;
|
|
this.animated.push(node); node.opacity = 0; node.scaleX = sx * startScale; node.scaleY = sy * startScale;
|
|
cc.tween(node).delay(delay).to(duration, { opacity, scaleX: sx, scaleY: sy }, { easing: 'backOut' }).start();
|
|
}
|
|
private play(height: number, designHeight: number): void {
|
|
this.openedAt = Date.now(); this.node.height = height;
|
|
this.node.on(cc.Node.EventType.TOUCH_END, (event: cc.Event) => {
|
|
event.stopPropagation(); if (Date.now() - this.openedAt > 350) this.node.destroy();
|
|
});
|
|
const shade = this.node.getChildByName('shade'); shade.height = height;
|
|
this.animated.push(shade); shade.opacity = 0; cc.tween(shade).to(0.2, { opacity: 255 }).start();
|
|
const stage = this.node.getChildByName('guide-stage');
|
|
const scale = Math.min(1, (height - 100) / stage.height);
|
|
stage.x = (this.node.width - stage.width * scale) / 2 + stage.x * scale;
|
|
stage.y = -(height - stage.height * scale) / 2 + (stage.y + (designHeight - stage.height) / 2) * scale;
|
|
stage.scaleX *= scale; stage.scaleY *= scale;
|
|
[['biaoti', 0.05], ['tuiy', 0.45], ['tuer', 1.35], ['tusan', 2.25]].forEach(pair => this.appear(stage.getChildByName(String(pair[0])), Number(pair[1])));
|
|
this.appear(stage.getChildByName('Arrow0'), 0.95, 0.32, 0.65);
|
|
this.appear(stage.getChildByName('Arrow1'), 1.85, 0.32, 0.65);
|
|
const hint = stage.getChildByName('继续点击'); this.animated.push(hint); hint.opacity = 0;
|
|
cc.tween(hint).delay(2.7).to(0.3, { opacity: 255 }).start();
|
|
}
|
|
onDestroy(): void { this.animated.forEach(node => cc.Tween.stopAllByTarget(node)); }
|
|
}
|