scatter和wild层级
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m19s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m19s
This commit is contained in:
parent
4c32b9f6bd
commit
7954f5ea43
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ import { gold2cash } from '../../Loading/scripts/comm';
|
|||||||
import { NodePoolManager } from '../../Loading/scripts/manager/NodePoolManager';
|
import { NodePoolManager } from '../../Loading/scripts/manager/NodePoolManager';
|
||||||
import { I18nManager } from '../../Loading/scripts/manager/I18nManager';
|
import { I18nManager } from '../../Loading/scripts/manager/I18nManager';
|
||||||
import { AudioManager } from '../../Loading/scripts/manager/AudioManager';
|
import { AudioManager } from '../../Loading/scripts/manager/AudioManager';
|
||||||
|
import { UpLayer } from './game/UpLayer';
|
||||||
let { ccclass, property } = _decorator;
|
let { ccclass, property } = _decorator;
|
||||||
|
|
||||||
//倍率瓶子的所在位置
|
//倍率瓶子的所在位置
|
||||||
@ -32,6 +33,9 @@ export class SlotGame extends Component {
|
|||||||
@property(Prefab)
|
@property(Prefab)
|
||||||
multiPre: Prefab = null;
|
multiPre: Prefab = null;
|
||||||
|
|
||||||
|
@property(UpLayer)
|
||||||
|
upLayer: UpLayer = null;
|
||||||
|
|
||||||
@property(Prefab)
|
@property(Prefab)
|
||||||
multiLabelPre: Prefab = null;
|
multiLabelPre: Prefab = null;
|
||||||
|
|
||||||
@ -225,9 +229,15 @@ export class SlotGame extends Component {
|
|||||||
|
|
||||||
// 初始化滚轮数据
|
// 初始化滚轮数据
|
||||||
initRollerWithIcon(gameInfo: any) {
|
initRollerWithIcon(gameInfo: any) {
|
||||||
|
this.upLayer.hideAllLayer();
|
||||||
|
this.rollerManager.setUpLayer(this.upLayer);
|
||||||
this.gameInfo = gameInfo;
|
this.gameInfo = gameInfo;
|
||||||
this.spinData = this.gameInfo.Data;
|
this.spinData = this.gameInfo.Data;
|
||||||
this.rollerManager.initRollerWithIcon(this.spinData);
|
this.rollerManager.initRollerWithIcon(this.spinData);
|
||||||
|
this.rollerManager.vRollers.forEach((roller) => {
|
||||||
|
this.upLayer.syncSpecialFromRoller(roller);
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setRollerIconRule(rollerIconRule: any) {
|
setRollerIconRule(rollerIconRule: any) {
|
||||||
@ -239,6 +249,7 @@ export class SlotGame extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spin(isFree: boolean) {
|
spin(isFree: boolean) {
|
||||||
|
this.upLayer.giveBackAllSpecials(this.rollerManager);
|
||||||
AudioManager.instance.playSFX('Spin_Button_Click');
|
AudioManager.instance.playSFX('Spin_Button_Click');
|
||||||
this.setWaysCount('...');
|
this.setWaysCount('...');
|
||||||
if (!isFree) {
|
if (!isFree) {
|
||||||
@ -602,6 +613,8 @@ export class SlotGame extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onRollerStop(rollerId: number) {
|
onRollerStop(rollerId: number) {
|
||||||
|
let roller = this.rollerManager.allRollers[rollerId];
|
||||||
|
this.upLayer.syncSpecialFromRoller(roller);
|
||||||
// if (rollerId < 1) return;
|
// if (rollerId < 1) return;
|
||||||
// 计算当前停止列之前的所有数字的乘积
|
// 计算当前停止列之前的所有数字的乘积
|
||||||
let totalWays = 1;
|
let totalWays = 1;
|
||||||
@ -632,6 +645,7 @@ export class SlotGame extends Component {
|
|||||||
|
|
||||||
// 新增:事件处理方法
|
// 新增:事件处理方法
|
||||||
onAllRollerIconsDeleted() {
|
onAllRollerIconsDeleted() {
|
||||||
|
this.upLayer.giveBackAllSpecials(this.rollerManager);
|
||||||
// 向上传递事件
|
// 向上传递事件
|
||||||
this.node.emit(SLOT_GAME_EVENT.ALL_ROLLER_ICONS_DELETED);
|
this.node.emit(SLOT_GAME_EVENT.ALL_ROLLER_ICONS_DELETED);
|
||||||
}
|
}
|
||||||
@ -642,6 +656,7 @@ export class SlotGame extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAllRollerIconsFallen() {
|
onAllRollerIconsFallen() {
|
||||||
|
this.upLayer.resetAndSyncAllSpecials(this.rollerManager);
|
||||||
// 向上传递事件
|
// 向上传递事件
|
||||||
this.node.emit(SLOT_GAME_EVENT.ALL_ROLLER_ICONS_FALLEN);
|
this.node.emit(SLOT_GAME_EVENT.ALL_ROLLER_ICONS_FALLEN);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,7 +70,7 @@ export abstract class BaseRoller extends Component {
|
|||||||
iconFactory: IconFactory = null;
|
iconFactory: IconFactory = null;
|
||||||
|
|
||||||
// 保护属性,子类可访问
|
// 保护属性,子类可访问
|
||||||
protected _rollerId: number = 0;
|
_rollerId: number = 0;
|
||||||
protected _view: Node = null;
|
protected _view: Node = null;
|
||||||
protected _content: Node = null;
|
protected _content: Node = null;
|
||||||
protected _info: Info = new Info();
|
protected _info: Info = new Info();
|
||||||
@ -608,7 +608,7 @@ export abstract class BaseRoller extends Component {
|
|||||||
return null; // 返回安全的默认值
|
return null; // 返回安全的默认值
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._content.getComponent(UITransform).convertToWorldSpaceAR(icon.position);
|
return icon.getWorldPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -243,6 +243,16 @@ export class Roller extends BaseRoller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNodeMsgFromPos(pos: number): { node: Node, start: number, height: number } | null {
|
||||||
|
let iconNode = this.getIconNode(pos);
|
||||||
|
if (!iconNode) return null;
|
||||||
|
|
||||||
|
let start = iconNode.getComponent(Icon).startPos;
|
||||||
|
let height = iconNode.getComponent(Icon).lHeight;
|
||||||
|
|
||||||
|
return { node: iconNode, start: start, height: height };
|
||||||
|
}
|
||||||
|
|
||||||
stopScrollWork(stopSpeedData: number[][]) {
|
stopScrollWork(stopSpeedData: number[][]) {
|
||||||
this._info.hasStopScrollWork = true;
|
this._info.hasStopScrollWork = true;
|
||||||
this.changeState(ROLLER_STATE.DECELERATE);
|
this.changeState(ROLLER_STATE.DECELERATE);
|
||||||
|
|||||||
@ -43,6 +43,8 @@ export class RollerManager extends Component {
|
|||||||
{ row: 5, col: 1 },
|
{ row: 5, col: 1 },
|
||||||
{ row: 5, col: 1 },
|
{ row: 5, col: 1 },
|
||||||
];
|
];
|
||||||
|
upLayer: any = null;
|
||||||
|
|
||||||
// 竖向滚轮数组
|
// 竖向滚轮数组
|
||||||
vRollers: Roller[] = [];
|
vRollers: Roller[] = [];
|
||||||
// 滚轮数组
|
// 滚轮数组
|
||||||
@ -134,6 +136,10 @@ export class RollerManager extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setUpLayer(upLayer: any) {
|
||||||
|
this.upLayer = upLayer;
|
||||||
|
}
|
||||||
|
|
||||||
registerEvent() {
|
registerEvent() {
|
||||||
for (let lx = 0; lx < this.allRollers.length; lx++) {
|
for (let lx = 0; lx < this.allRollers.length; lx++) {
|
||||||
let roller = this.allRollers[lx];
|
let roller = this.allRollers[lx];
|
||||||
@ -566,6 +572,8 @@ export class RollerManager extends Component {
|
|||||||
roller.setCroSymbols(rollerCroSymbols);
|
roller.setCroSymbols(rollerCroSymbols);
|
||||||
roller.manualStopScroll(stopData)
|
roller.manualStopScroll(stopData)
|
||||||
}
|
}
|
||||||
|
this.upLayer.resetAndSyncAllSpecials(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对服务器下发的数据进行操作
|
// 对服务器下发的数据进行操作
|
||||||
@ -633,6 +641,7 @@ export class RollerManager extends Component {
|
|||||||
uniquePositions.forEach(pos => {
|
uniquePositions.forEach(pos => {
|
||||||
let iconNode = this.getIconNode(pos);
|
let iconNode = this.getIconNode(pos);
|
||||||
if (iconNode) {
|
if (iconNode) {
|
||||||
|
this.upLayer.removeSpecialByNode(iconNode);
|
||||||
// 保存原始父节点和位置信息到Map中
|
// 保存原始父节点和位置信息到Map中
|
||||||
this.winIconNodeMap.set(pos, {
|
this.winIconNodeMap.set(pos, {
|
||||||
node: iconNode,
|
node: iconNode,
|
||||||
|
|||||||
99
assets/Game/scripts/game/UpLayer.ts
Normal file
99
assets/Game/scripts/game/UpLayer.ts
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
import { _decorator, Component, instantiate, Node, sp, tween, UIOpacity, UITransform, v3 } from 'cc';
|
||||||
|
import { PREVIEW } from 'cc/env';
|
||||||
|
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)
|
||||||
|
wildLayer: Node = null;
|
||||||
|
|
||||||
|
@property(Node)
|
||||||
|
scatterLayer: Node = null;
|
||||||
|
|
||||||
|
|
||||||
|
// 统一隐藏所有层
|
||||||
|
hideAllLayer() {
|
||||||
|
this.wildLayer.active = false;
|
||||||
|
this.scatterLayer.active = false;
|
||||||
|
}
|
||||||
|
// ---------------------------------------readyHandNode、scatterLayer、wildLayer相关 ---------------------------------------
|
||||||
|
adopted = new Map<Node, { rollerId: number; startPos: number; height: number; type: 'wild' | 'scatter' }>();
|
||||||
|
|
||||||
|
|
||||||
|
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.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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
9
assets/Game/scripts/game/UpLayer.ts.meta
Normal file
9
assets/Game/scripts/game/UpLayer.ts.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "55162d22-5267-4d67-9e5d-d56c2cc460eb",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user