212 lines
6.9 KiB
TypeScript
212 lines
6.9 KiB
TypeScript
import { _decorator, Component, instantiate, Node, Prefab, sp, tween, UIOpacity, UITransform, v3 } from 'cc';
|
|
import { Icon } from './Icon';
|
|
import { Roller } from './Roller';
|
|
import { RollerManager } from './RollerManager';
|
|
let { ccclass, property } = _decorator;
|
|
|
|
@ccclass('UpLayer')
|
|
export class UpLayer extends Component {
|
|
@property(Node)
|
|
readHandLayer: Node = null;
|
|
|
|
@property(Node)
|
|
wildLayer: Node = null;
|
|
|
|
@property(Node)
|
|
readyHandGrayNode: Node = null;
|
|
|
|
@property(Node)
|
|
scatterLayer: Node = null;
|
|
|
|
@property(Node)
|
|
readyHandNode: Node = null;
|
|
|
|
@property(Node)
|
|
winLayer: Node = null;
|
|
|
|
@property(Node)
|
|
winGrayLayer: Node = null;
|
|
|
|
@property(Node)
|
|
winSpineLayer: Node = null;
|
|
|
|
@property(Node)
|
|
winIconLayer: Node = null;
|
|
|
|
@property(Prefab)
|
|
winSpinePrefab: Prefab = null;
|
|
|
|
// 统一隐藏所有层
|
|
hideAllLayer() {
|
|
this.readHandLayer.active = false;
|
|
this.wildLayer.active = false;
|
|
this.readyHandGrayNode.active = false;
|
|
this.scatterLayer.active = false;
|
|
this.readyHandNode.active = false;
|
|
|
|
this.winLayer.active = false;
|
|
this.winGrayLayer.active = false;
|
|
this.winSpineLayer.active = false;
|
|
this.winIconLayer.active = false;
|
|
}
|
|
|
|
|
|
// ---------------------------------------winIconLayer相关 ---------------------------------------
|
|
setWinLayerActive(bol: boolean) {
|
|
this.winLayer.active = bol;
|
|
this.winIconLayer.active = bol;
|
|
this.winSpineLayer.active = bol;
|
|
this.setWinGrayNode(bol);
|
|
}
|
|
|
|
setWinGrayNode(bool: boolean) {
|
|
this.winLayer.active = true;
|
|
this.winSpineLayer.active = true;
|
|
let uiOpacity = this.winGrayLayer.getComponent(UIOpacity);
|
|
if (bool) {
|
|
this.winGrayLayer.active = bool;
|
|
uiOpacity.opacity = 0;
|
|
tween(uiOpacity)
|
|
.to(0.1, { opacity: 255 })
|
|
.start();
|
|
} else {
|
|
uiOpacity.opacity = 255;
|
|
tween(uiOpacity)
|
|
.to(0.1, { opacity: 0 })
|
|
.call(() => {
|
|
this.winLayer.active = false;
|
|
this.winSpineLayer.active = false;
|
|
this.winGrayLayer.active = bool;
|
|
})
|
|
.start();
|
|
}
|
|
}
|
|
|
|
playIconWinAni(iconNode: Node) {
|
|
this.winLayer.active = true;
|
|
this.winSpineLayer.active = true;
|
|
this.winIconLayer.active = true;
|
|
let iconWorldPosition = iconNode.getWorldPosition();
|
|
let iconLocalPosition = this.winIconLayer.getComponent(UITransform).convertToNodeSpaceAR(iconWorldPosition);
|
|
iconNode.parent = this.winIconLayer;
|
|
iconNode.setPosition(iconLocalPosition);
|
|
iconNode.getComponent(Icon).playBounceSpine();
|
|
|
|
let winSpineNode = instantiate(this.winSpinePrefab);
|
|
let spine = winSpineNode.getChildByName('spine').getComponent(sp.Skeleton);
|
|
winSpineNode.parent = this.winSpineLayer;
|
|
winSpineNode.setPosition(iconLocalPosition);
|
|
winSpineNode.setSiblingIndex(9999);
|
|
spine.setCompleteListener(null);
|
|
spine.setCompleteListener(() => {
|
|
winSpineNode.destroy();
|
|
});
|
|
spine.setAnimation(0, 'animation', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------readyHandNode、scatterLayer、wildLayer相关 ---------------------------------------
|
|
adopted = new Map<Node, { rollerId: number; startPos: number; height: number; type: 'wild' | 'scatter' }>();
|
|
|
|
hideReadHandLayer() {
|
|
this.readHandLayer.active = false;
|
|
}
|
|
|
|
setSpecialLayersActive() {
|
|
let hasWild = Array.from(this.adopted.values()).some(v => v.type === 'wild');
|
|
let hasScatter = Array.from(this.adopted.values()).some(v => v.type === 'scatter');
|
|
this.readHandLayer.active = hasWild || hasScatter;
|
|
this.wildLayer.active = hasWild;
|
|
this.scatterLayer.active = hasScatter;
|
|
}
|
|
|
|
adoptSpecial(node: Node, rollerId: number, startPos: number, height: number, type: 'wild' | 'scatter') {
|
|
if (!node || !node.isValid) return;
|
|
if (this.adopted.has(node)) return;
|
|
|
|
let wp = node.worldPosition.clone();
|
|
let layer = type === 'wild' ? this.wildLayer : this.scatterLayer;
|
|
layer.active = true;
|
|
|
|
node.parent = layer;
|
|
node.setWorldPosition(wp);
|
|
node.setSiblingIndex(9999);
|
|
|
|
this.adopted.set(node, { rollerId, startPos, height, type });
|
|
this.setSpecialLayersActive();
|
|
}
|
|
|
|
// 增量同步某列(停轮/单列落定时可用)
|
|
syncSpecialFromRoller(roller: Roller) {
|
|
if (!roller) return;
|
|
let seen = new Set<Node>();
|
|
for (let i = 0; i < roller.row; i++) {
|
|
let n = (roller as any).getIconNode(i);
|
|
if (!n || seen.has(n)) continue;
|
|
seen.add(n);
|
|
|
|
let icon = n.getComponent(Icon);
|
|
if (!icon || !icon.isWildOrScatter) continue;
|
|
|
|
let msg = (roller as any).getNodeMsgFromPos(i);
|
|
if (!msg) continue;
|
|
|
|
let type: 'wild' | 'scatter' = icon.index === 0 ? 'wild' : 'scatter';
|
|
this.adoptSpecial(msg.node, roller.rollerId, msg.start, msg.height, type);
|
|
}
|
|
}
|
|
|
|
// 删除前:去登记,避免后续“归还”
|
|
removeSpecialByNode(node: Node) {
|
|
if (!node) return;
|
|
if (this.adopted.delete(node)) this.setSpecialLayersActive();
|
|
}
|
|
|
|
// 统一归还(开新轮或重算前调用)
|
|
giveBackAllSpecials(rm: RollerManager) {
|
|
if (!rm) return;
|
|
this.adopted.forEach((info, node) => {
|
|
if (!node || !node.isValid) return;
|
|
let roller = rm.allRollers[info.rollerId];
|
|
if (!roller) return;
|
|
node.parent = roller.node;
|
|
node.setPosition(roller.getIconPosition(info.startPos, info.height));
|
|
});
|
|
this.adopted.clear();
|
|
this.setSpecialLayersActive();
|
|
}
|
|
|
|
// 全量重算:不累加,重新扫描所有列
|
|
resetAndSyncAllSpecials(rm: RollerManager) {
|
|
if (!rm) return;
|
|
this.giveBackAllSpecials(rm); // 清空旧数据与节点
|
|
for (let i = 0; i < rm.allRollers.length; i++) {
|
|
this.syncSpecialFromRoller(rm.allRollers[i]);
|
|
}
|
|
}
|
|
|
|
playReadyHandAni(rollerId: number) {
|
|
this.readHandLayer.active = true;
|
|
this.setReadHandSkeletonActive(true);
|
|
this.readyHandNode.getComponent(sp.Skeleton).setAnimation(0, 'animation', true);
|
|
|
|
this.readyHandGrayNode.children.forEach(child => child.active = true)
|
|
this.readyHandGrayNode.children[rollerId].active = false;
|
|
|
|
this.readyHandNode.setPosition(this.readyHandGrayNode.children[rollerId].position.clone());
|
|
}
|
|
|
|
setReadHandSkeletonActive(bol: boolean) {
|
|
this.readyHandNode.active = bol;
|
|
this.readyHandGrayNode.active = bol;
|
|
}
|
|
|
|
playScatterSpine(bol: boolean) {
|
|
this.scatterLayer.children.forEach(child => child.getComponent(Icon).playScatterWaitSpine(bol));
|
|
}
|
|
}
|
|
|