|
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { Color, instantiate, Label, Layout, Node, Sprite } from 'cc'; |
|
|
|
|
import { Color, instantiate, Label, Layout, Node, Sprite, UITransform } from 'cc'; |
|
|
|
|
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; |
|
|
|
|
import { GBundle, GPath } from '../../game/ConfigRes'; |
|
|
|
|
import { BattleBuffCarryStore } from '../../manager/battleBuff/BattleBuffCarryStore'; |
|
|
|
|
@ -19,6 +19,12 @@ const PASSIVE_NAME_OUTLINE_HEX: Record<number, string> = { |
|
|
|
|
3: '#623073', |
|
|
|
|
4: '#734930', |
|
|
|
|
}; |
|
|
|
|
/** 敌方被动:左右各最多展示数 */ |
|
|
|
|
const PASSIVE_PER_SIDE = 3; |
|
|
|
|
/** 右侧被动列表节点名(运行时创建) */ |
|
|
|
|
const PASSIVE_RIGHT_NAME = 'ui_otherskill2ListR'; |
|
|
|
|
/** 左右列表贴向屏幕中线的间距(父节点本地像素) */ |
|
|
|
|
const PASSIVE_CENTER_GAP = 16; |
|
|
|
|
|
|
|
|
|
/** 敌方被动格:仅展示,不触发玩家侧 CD 产字 */ |
|
|
|
|
class BattleGameOtherPassiveSlot { |
|
|
|
|
@ -175,12 +181,14 @@ class BattleGameOtherPassiveSlot { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 战斗界面敌方 buff:ui_otherskill1List(主动)/ ui_otherskill2List(被动)。 |
|
|
|
|
* 被动左右最多各 3 个;右侧列表运行时镜像创建。 |
|
|
|
|
* 仅展示与同步 AI CD,不可拖拽。 |
|
|
|
|
*/ |
|
|
|
|
export class BattleGameOtherSkillView { |
|
|
|
|
private readonly _active1: BattleGameDailyShopSkillSlot | null; |
|
|
|
|
private readonly _active2: BattleGameDailyShopSkillSlot | null; |
|
|
|
|
private readonly _passiveRoot: Node | null; |
|
|
|
|
private _passiveRightRoot: Node | null = null; |
|
|
|
|
private readonly _passiveTemplate: Node | null; |
|
|
|
|
private readonly _passiveSlots: BattleGameOtherPassiveSlot[] = []; |
|
|
|
|
private readonly _passiveNodes: Node[] = []; |
|
|
|
|
@ -364,24 +372,95 @@ export class BattleGameOtherSkillView { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 重建被动列表。 |
|
|
|
|
* 重建被动列表:前 3 个左、后 3 个右;超出截断并 warn。 |
|
|
|
|
* @param passives 携带列表 |
|
|
|
|
*/ |
|
|
|
|
private _rebuildPassives(passives: DailyShopParsed[]): void { |
|
|
|
|
this._clearPassives(); |
|
|
|
|
const root = this._passiveRoot; |
|
|
|
|
const left = this._passiveRoot; |
|
|
|
|
const template = this._passiveTemplate; |
|
|
|
|
if (!root?.isValid || !template?.isValid) return; |
|
|
|
|
for (let i = 0; i < passives.length; i++) { |
|
|
|
|
if (!left?.isValid || !template?.isValid) return; |
|
|
|
|
const maxTotal = PASSIVE_PER_SIDE * 2; |
|
|
|
|
if (passives.length > maxTotal) { |
|
|
|
|
console.warn('[BattleGame] 敌方被动超过左右各3,截断', passives.length, maxTotal); |
|
|
|
|
} |
|
|
|
|
const count = Math.min(passives.length, maxTotal); |
|
|
|
|
const needRight = count > PASSIVE_PER_SIDE; |
|
|
|
|
const right = needRight ? this._ensurePassiveRightRoot() : null; |
|
|
|
|
if (this._passiveRightRoot?.isValid) { |
|
|
|
|
this._passiveRightRoot.active = needRight; |
|
|
|
|
} |
|
|
|
|
for (let i = 0; i < count; i++) { |
|
|
|
|
const parent = i < PASSIVE_PER_SIDE ? left : right; |
|
|
|
|
if (!parent?.isValid) { |
|
|
|
|
console.warn('[BattleGame] 敌方被动父节点无效', i); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
const item = instantiate(template); |
|
|
|
|
item.active = true; |
|
|
|
|
item.setParent(root); |
|
|
|
|
item.setParent(parent); |
|
|
|
|
const slot = new BattleGameOtherPassiveSlot(item); |
|
|
|
|
slot.bind(passives[i]); |
|
|
|
|
this._passiveNodes.push(item); |
|
|
|
|
this._passiveSlots.push(slot); |
|
|
|
|
} |
|
|
|
|
root.getComponent(Layout)?.updateLayout(); |
|
|
|
|
this._layoutPassiveSide(left, true); |
|
|
|
|
if (right?.isValid) this._layoutPassiveSide(right, false); |
|
|
|
|
left.getComponent(Layout)?.updateLayout(); |
|
|
|
|
right?.getComponent(Layout)?.updateLayout(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 左右都从左往右排,并贴向中线:左组右缘、右组左缘靠近中间。 |
|
|
|
|
* @param node 列表根 |
|
|
|
|
* @param isLeft 是否左侧 |
|
|
|
|
*/ |
|
|
|
|
private _layoutPassiveSide(node: Node, isLeft: boolean): void { |
|
|
|
|
const ut = node.getComponent(UITransform); |
|
|
|
|
if (ut) ut.setAnchorPoint(isLeft ? 1 : 0, ut.anchorPoint.y); |
|
|
|
|
const layout = node.getComponent(Layout); |
|
|
|
|
if (layout) layout.horizontalDirection = Layout.HorizontalDirection.LEFT_TO_RIGHT; |
|
|
|
|
const p = node.position; |
|
|
|
|
node.setPosition(isLeft ? -PASSIVE_CENTER_GAP : PASSIVE_CENTER_GAP, p.y, p.z); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 右侧被动列表:与左侧同高、同缩放,从左往右排。 |
|
|
|
|
*/ |
|
|
|
|
private _ensurePassiveRightRoot(): Node | null { |
|
|
|
|
if (this._passiveRightRoot?.isValid) return this._passiveRightRoot; |
|
|
|
|
const left = this._passiveRoot; |
|
|
|
|
const parent = left?.parent; |
|
|
|
|
if (!left?.isValid || !parent?.isValid) { |
|
|
|
|
console.warn('[BattleGame] 无法创建敌方被动右侧列表'); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
let right = parent.getChildByName(PASSIVE_RIGHT_NAME); |
|
|
|
|
if (!right?.isValid) { |
|
|
|
|
right = new Node(PASSIVE_RIGHT_NAME); |
|
|
|
|
right.parent = parent; |
|
|
|
|
const lut = left.getComponent(UITransform); |
|
|
|
|
const rut = right.addComponent(UITransform); |
|
|
|
|
if (lut) { |
|
|
|
|
rut.setContentSize(lut.contentSize); |
|
|
|
|
rut.setAnchorPoint(0, lut.anchorPoint.y); |
|
|
|
|
} else { |
|
|
|
|
rut.setAnchorPoint(0, 0.5); |
|
|
|
|
} |
|
|
|
|
const ll = left.getComponent(Layout); |
|
|
|
|
const rl = right.addComponent(Layout); |
|
|
|
|
rl.type = Layout.Type.HORIZONTAL; |
|
|
|
|
rl.resizeMode = ll?.resizeMode ?? Layout.ResizeMode.CONTAINER; |
|
|
|
|
rl.spacingX = ll?.spacingX ?? 10; |
|
|
|
|
rl.paddingLeft = ll?.paddingLeft ?? 0; |
|
|
|
|
rl.paddingRight = ll?.paddingRight ?? 0; |
|
|
|
|
rl.horizontalDirection = Layout.HorizontalDirection.LEFT_TO_RIGHT; |
|
|
|
|
const ls = left.scale; |
|
|
|
|
right.setScale(ls.x, ls.y, ls.z); |
|
|
|
|
right.setPosition(PASSIVE_CENTER_GAP, left.position.y, left.position.z); |
|
|
|
|
} |
|
|
|
|
this._passiveRightRoot = right; |
|
|
|
|
return right; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** @param listRoot 被动列表根 */ |
|
|
|
|
@ -402,5 +481,8 @@ export class BattleGameOtherSkillView { |
|
|
|
|
} |
|
|
|
|
this._passiveNodes.length = 0; |
|
|
|
|
this._passiveSlots.length = 0; |
|
|
|
|
if (this._passiveRightRoot?.isValid) { |
|
|
|
|
this._passiveRightRoot.active = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|