You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/script/ui/BattleGame/BattleGameDailyShopSkillCli...

93 lines
3.4 KiB

3 weeks ago
import { EventTouch, Node } from 'cc';
import type { CocosBagBoardView } from '../../battle/view/CocosBagBoardView';
import type { ProjectBattleHandle } from '../../battle/runtime/BattleRuntime';
import { resolveBattleGameSkillClickKind } from '../../manager/battleBuff/BattleBuffActiveSkillUtil';
import type { BattleGameDailyShopSkillView } from './BattleGameDailyShopSkillView';
/** skill1 / skill2 点击施放(当前无点击类 buff) */
export class BattleGameDailyShopSkillClick {
private _skillView: BattleGameDailyShopSkillView | null = null;
private _bagView: CocosBagBoardView | null = null;
private _battle: ProjectBattleHandle | null = null;
private readonly _slotNodes: Node[] = [];
/** 绑定点击施放(需在 bagView bind 之后) */
bind(
skillView: BattleGameDailyShopSkillView | null,
bagView: CocosBagBoardView | null,
battle: ProjectBattleHandle | null,
): void {
this.unbind();
this._skillView = skillView;
this._bagView = bagView;
this._battle = battle;
this._bindSlotNodes();
}
/** roll 后刷新 skill 点击绑定(不重建 Click) */
refreshSlotBindings(): void {
for (const node of this._slotNodes) {
if (!node?.isValid) continue;
node.off(Node.EventType.TOUCH_END, this._onTouchEnd, this);
}
this._slotNodes.length = 0;
this._bindSlotNodes();
}
/** 注销触摸 */
unbind(): void {
for (const node of this._slotNodes) {
if (!node?.isValid) continue;
node.off(Node.EventType.TOUCH_END, this._onTouchEnd, this);
}
this._slotNodes.length = 0;
this._skillView = null;
this._bagView = null;
this._battle = null;
}
/** 为点击类 skill 注册 TOUCH_END(携带即注册;施放时动态解析 cast 类型) */
private _bindSlotNodes(): void {
const view = this._skillView;
if (!view) return;
for (let slotIndex = 0; slotIndex < 2; slotIndex++) {
const slot = view.getSlot(slotIndex);
const root = slot?.root;
if (!root?.isValid || !root.active || !slot.hasCarriedBuff()) continue;
root.on(Node.EventType.TOUCH_END, this._onTouchEnd, this);
root['battleShopSkillClickSlotIndex'] = slotIndex;
this._slotNodes.push(root);
}
}
/** 点击 skill 槽位 */
private _onTouchEnd(event: EventTouch): void {
const slotIndex = this._resolveSlotIndex(event);
if (slotIndex < 0) return;
const skillView = this._skillView;
const bagView = this._bagView;
const battle = this._battle;
if (!skillView || !battle) return;
if (bagView && !bagView.isBattleBuffSkillEnabled()) return;
const slot = skillView.getSlot(slotIndex);
if (!slot?.isReady() || !slot.isClickSkill()) return;
const row = slot.getBuffRow();
const kind = resolveBattleGameSkillClickKind(row);
if (kind == null) return;
}
/** 从节点反查槽位下标 */
private _resolveSlotIndex(event: EventTouch): number {
let cur = event.target as Node | null;
while (cur?.isValid) {
const idx = cur['battleShopSkillClickSlotIndex'];
if (typeof idx === 'number') return idx;
cur = cur.parent;
}
return -1;
}
}