|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Label, Layout, Node, Sprite, UITransform, Vec3, isValid } from 'cc'; |
|
|
|
import { Label, Node, UITransform, Vec3, isValid } from 'cc'; |
|
|
|
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; |
|
|
|
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; |
|
|
|
import { TableNames } from '../../../game/ConfigTableData'; |
|
|
|
import { TableNames } from '../../../game/ConfigTableData'; |
|
|
|
import { GBundle, GPath } from '../../../game/ConfigRes'; |
|
|
|
import { GBundle, GPath } from '../../../game/ConfigRes'; |
|
|
|
@ -9,14 +9,18 @@ import { MapGrid } from './MapGrid'; |
|
|
|
const LOCK_TIP_PATH = 'prefab/'; |
|
|
|
const LOCK_TIP_PATH = 'prefab/'; |
|
|
|
/** 解锁条件气泡预制体名 */ |
|
|
|
/** 解锁条件气泡预制体名 */ |
|
|
|
const LOCK_TIP_NAME = '格子锁'; |
|
|
|
const LOCK_TIP_NAME = '格子锁'; |
|
|
|
/** 预制体上显示数字的子节点名 */ |
|
|
|
/** 锁与数字容器 */ |
|
|
|
|
|
|
|
const LOCK_TIP_LOCK = 'lock'; |
|
|
|
|
|
|
|
/** 预制体上显示数字的子节点名(在 lock 下) */ |
|
|
|
const LOCK_TIP_NUM = 'num'; |
|
|
|
const LOCK_TIP_NUM = 'num'; |
|
|
|
/** 动态条件图标子节点名前缀 */ |
|
|
|
|
|
|
|
const LOCK_TIP_COND = 'cond_'; |
|
|
|
|
|
|
|
/** 三选一宝箱提示子节点 */ |
|
|
|
/** 三选一宝箱提示子节点 */ |
|
|
|
const LOCK_TIP_BOX = 'box'; |
|
|
|
const LOCK_TIP_BOX = 'box'; |
|
|
|
/** 条件图标占位尺寸(与 icons/img 五行图接近) */ |
|
|
|
/** 五行属性图标子节点 */ |
|
|
|
const COND_ICON_SIZE = 22; |
|
|
|
const LOCK_TIP_FIVE = 'five'; |
|
|
|
|
|
|
|
/** 无宝箱时 lock 的本地 Y */ |
|
|
|
|
|
|
|
const LOCK_Y_NO_BOX = 0; |
|
|
|
|
|
|
|
/** 有宝箱时 lock 的本地 Y */ |
|
|
|
|
|
|
|
const LOCK_Y_WITH_BOX = -15; |
|
|
|
/** 气泡世界坐标转本地时复用 */ |
|
|
|
/** 气泡世界坐标转本地时复用 */ |
|
|
|
const _tipWorld = new Vec3(); |
|
|
|
const _tipWorld = new Vec3(); |
|
|
|
/** 气泡本地坐标复用 */ |
|
|
|
/** 气泡本地坐标复用 */ |
|
|
|
@ -297,19 +301,18 @@ export class MapAreaUnlock { |
|
|
|
this._tipCamps.push(0); |
|
|
|
this._tipCamps.push(0); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
const numNode = tip.getChildByName(LOCK_TIP_NUM); |
|
|
|
const lock = tip.getChildByName(LOCK_TIP_LOCK); |
|
|
|
const label = numNode?.getComponent(Label); |
|
|
|
const label = lock?.getChildByName(LOCK_TIP_NUM)?.getComponent(Label); |
|
|
|
if (!label) { |
|
|
|
if (!label) { |
|
|
|
console.warn('[MapAreaUnlock] 格子锁缺少 num Label'); |
|
|
|
console.warn('[MapAreaUnlock] 格子锁缺少 lock/num Label'); |
|
|
|
tip.active = false; |
|
|
|
tip.active = false; |
|
|
|
this._tipCamps.push(0); |
|
|
|
this._tipCamps.push(0); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
label.string = String(jobs[i].num); |
|
|
|
label.string = String(jobs[i].num); |
|
|
|
this._syncCondIcons(tip, jobs[i].heroType); |
|
|
|
this._syncFiveIcon(tip, jobs[i].heroType); |
|
|
|
const nextCount = this.completedCount(jobs[i].camp) + 1; |
|
|
|
const nextCount = this.completedCount(jobs[i].camp) + 1; |
|
|
|
this._syncBoxVisible(tip, this._isSelectTriggerCount(nextCount)); |
|
|
|
this._syncBoxVisible(tip, this._isSelectTriggerCount(nextCount)); |
|
|
|
tip.getComponent(Layout)?.updateLayout(); |
|
|
|
|
|
|
|
this._placeTipCenter(tip, jobs[i].grids); |
|
|
|
this._placeTipCenter(tip, jobs[i].grids); |
|
|
|
tip.active = true; |
|
|
|
tip.active = true; |
|
|
|
this._tipCamps.push(jobs[i].camp); |
|
|
|
this._tipCamps.push(jobs[i].camp); |
|
|
|
@ -321,7 +324,7 @@ export class MapAreaUnlock { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 下次解锁是否触发三选一时显示 box。 |
|
|
|
* 下次解锁是否触发三选一时显示 box,并调整 lock 的 Y。 |
|
|
|
* @param tip 格子锁气泡 |
|
|
|
* @param tip 格子锁气泡 |
|
|
|
* @param show 是否显示 |
|
|
|
* @param show 是否显示 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -332,6 +335,13 @@ export class MapAreaUnlock { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
box.active = show; |
|
|
|
box.active = show; |
|
|
|
|
|
|
|
const lock = tip.getChildByName(LOCK_TIP_LOCK); |
|
|
|
|
|
|
|
if (!lock) { |
|
|
|
|
|
|
|
console.warn('[MapAreaUnlock] 格子锁缺少 lock'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const pos = lock.position; |
|
|
|
|
|
|
|
lock.setPosition(pos.x, show ? LOCK_Y_WITH_BOX : LOCK_Y_NO_BOX, pos.z); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -349,67 +359,31 @@ export class MapAreaUnlock { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 同步解锁条件五行图标:类型 0 不加载;1–5 各挂一张对应图标(锁与数字之间)。 |
|
|
|
* 同步 five 五行图标:类型 0 隐藏;1–5 显示并加载对应图标。 |
|
|
|
* @param tip 格子锁气泡 |
|
|
|
* @param tip 格子锁气泡 |
|
|
|
* @param heroType 当前随机到的 Hero.herotype;0 为无属性限制 |
|
|
|
* @param heroType 当前随机到的 Hero.herotype;0 为无属性限制 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private _syncCondIcons(tip: Node, heroType: number): void { |
|
|
|
private _syncFiveIcon(tip: Node, heroType: number): void { |
|
|
|
this._clearCondIcons(tip); |
|
|
|
const five = tip.getChildByName(LOCK_TIP_FIVE); |
|
|
|
const names = this._condIconNames(heroType); |
|
|
|
if (!five) { |
|
|
|
if (names.length <= 0) return; |
|
|
|
console.warn('[MapAreaUnlock] 格子锁缺少 five'); |
|
|
|
const numNode = tip.getChildByName(LOCK_TIP_NUM); |
|
|
|
return; |
|
|
|
let insertAt = numNode ? numNode.getSiblingIndex() : tip.children.length; |
|
|
|
|
|
|
|
for (let i = 0; i < names.length; i++) { |
|
|
|
|
|
|
|
const icon = this._makeCondIcon(names[i]); |
|
|
|
|
|
|
|
tip.insertChild(icon, insertAt); |
|
|
|
|
|
|
|
insertAt++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 当前条件需要展示的五行图标名列表;无限制返回空。 |
|
|
|
|
|
|
|
* @param heroType Hero.herotype |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private _condIconNames(heroType: number): string[] { |
|
|
|
|
|
|
|
const type = Math.floor(Number(heroType) || 0); |
|
|
|
const type = Math.floor(Number(heroType) || 0); |
|
|
|
if (type <= 0) return []; |
|
|
|
if (type <= 0) { |
|
|
|
|
|
|
|
five.active = false; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
const name = HERO_TYPE_ICON[type]; |
|
|
|
const name = HERO_TYPE_ICON[type]; |
|
|
|
if (!name) { |
|
|
|
if (!name) { |
|
|
|
console.warn('[MapAreaUnlock] 未知解锁 herotype,无法加载条件图标', type); |
|
|
|
console.warn('[MapAreaUnlock] 未知解锁 herotype,无法加载属性图标', type); |
|
|
|
return []; |
|
|
|
five.active = false; |
|
|
|
} |
|
|
|
return; |
|
|
|
return [name]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 创建单张条件图标节点(SpriteLoad 从 icons 包加载)。 |
|
|
|
|
|
|
|
* @param name 金/木/水/火/土 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private _makeCondIcon(name: string): Node { |
|
|
|
|
|
|
|
const node = new Node(LOCK_TIP_COND + name); |
|
|
|
|
|
|
|
node.layer = 33554432; |
|
|
|
|
|
|
|
const ut = node.addComponent(UITransform); |
|
|
|
|
|
|
|
ut.setContentSize(COND_ICON_SIZE, COND_ICON_SIZE); |
|
|
|
|
|
|
|
const sp = node.addComponent(Sprite); |
|
|
|
|
|
|
|
sp.sizeMode = Sprite.SizeMode.TRIMMED; |
|
|
|
|
|
|
|
node.addComponent(SpriteLoad).setSprite(GPath.ElementAttr(name), GBundle.Items); |
|
|
|
|
|
|
|
return node; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 清除气泡上动态挂的条件图标(池化复用前必须清干净)。 |
|
|
|
|
|
|
|
* @param tip 格子锁气泡 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private _clearCondIcons(tip: Node): void { |
|
|
|
|
|
|
|
if (!tip?.isValid) return; |
|
|
|
|
|
|
|
const children = tip.children; |
|
|
|
|
|
|
|
for (let i = children.length - 1; i >= 0; i--) { |
|
|
|
|
|
|
|
const child = children[i]; |
|
|
|
|
|
|
|
if (!child?.isValid) continue; |
|
|
|
|
|
|
|
if (child.name.indexOf(LOCK_TIP_COND) !== 0) continue; |
|
|
|
|
|
|
|
child.removeFromParent(); |
|
|
|
|
|
|
|
child.destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
five.active = true; |
|
|
|
|
|
|
|
let sl = five.getComponent(SpriteLoad); |
|
|
|
|
|
|
|
if (!sl) sl = five.addComponent(SpriteLoad); |
|
|
|
|
|
|
|
sl.setSprite(GPath.ElementAttr(name), GBundle.Items); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -529,7 +503,8 @@ export class MapAreaUnlock { |
|
|
|
for (let i = 0; i < this._tips.length; i++) { |
|
|
|
for (let i = 0; i < this._tips.length; i++) { |
|
|
|
const tip = this._tips[i]; |
|
|
|
const tip = this._tips[i]; |
|
|
|
if (!tip || !isValid(tip)) continue; |
|
|
|
if (!tip || !isValid(tip)) continue; |
|
|
|
this._clearCondIcons(tip); |
|
|
|
const five = tip.getChildByName(LOCK_TIP_FIVE); |
|
|
|
|
|
|
|
if (five?.isValid) five.active = false; |
|
|
|
if (tip['resKey']) gg.res.putNode(tip); |
|
|
|
if (tip['resKey']) gg.res.putNode(tip); |
|
|
|
else tip.destroy(); |
|
|
|
else tip.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|