refactor(map): 调整英雄列表布局参数与添加页签红点逻辑
1. 新增英雄列表卡片宽度、间距、边距可配置属性,修正列表内容宽度计算 2. 为任务主页添加英雄成长和天赋更新事件监听,实现页签红点自动刷新 3. 补充全英雄可升级状态检测与红点显示逻辑
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -114,6 +114,18 @@ export class HerosListComp extends CCComp {
|
||||
@property(RichText)
|
||||
upgrade_info_label = null!
|
||||
|
||||
/** 卡片宽度 */
|
||||
@property
|
||||
card_w = 120
|
||||
|
||||
/** 卡片横向间隔 */
|
||||
@property
|
||||
spacing_x = 10
|
||||
|
||||
/** 卡片左右边距 */
|
||||
@property
|
||||
margin_x = 15
|
||||
|
||||
// ======================== 运行时状态 ========================
|
||||
|
||||
huuid: number = 0
|
||||
@@ -364,6 +376,11 @@ export class HerosListComp extends CCComp {
|
||||
const total = this.cards_node.children.length
|
||||
if (total === 0) return
|
||||
|
||||
// 宽度 = 卡片总宽 + 卡片间隔 + 左右边距
|
||||
const contentW = total * this.card_w
|
||||
+ (total - 1) * this.spacing_x
|
||||
+ this.margin_x * 2
|
||||
|
||||
const cols = 4
|
||||
const rows = Math.ceil(total / cols)
|
||||
const cardH = 200
|
||||
@@ -372,11 +389,11 @@ export class HerosListComp extends CCComp {
|
||||
|
||||
const uiTrans = this.cards_node.getComponent(UITransform)
|
||||
if (uiTrans) {
|
||||
uiTrans.setContentSize(uiTrans.width, contentH)
|
||||
uiTrans.setContentSize(contentW, contentH)
|
||||
}
|
||||
|
||||
mLogger.log(this.debugMode, "HerosListComp", "updateContentSize", {
|
||||
total, cols, rows, contentH,
|
||||
total, cols, rows, contentW, contentH,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import { GameEvent } from "../common/config/GameEvent";
|
||||
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { HeroList } from "../common/config/heroSet";
|
||||
import { canHeroUpgrade } from "../common/config/heroUpSet";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -84,6 +86,14 @@ export class MissionHomeComp extends CCComp {
|
||||
/** 注册任务结束事件 */
|
||||
protected onLoad(): void {
|
||||
this.on(GameEvent.MissionEnd, this.mission_end, this)
|
||||
// oops.message 事件总线:成长/天赋数据变化时刷新页签红点
|
||||
oops.message.on(GameEvent.HERO_GROWTH_UPDATE, this.refreshRedDots, this)
|
||||
oops.message.on(GameEvent.TALENT_UPDATE, this.refreshRedDots, this)
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
oops.message.off(GameEvent.HERO_GROWTH_UPDATE, this.refreshRedDots, this)
|
||||
oops.message.off(GameEvent.TALENT_UPDATE, this.refreshRedDots, this)
|
||||
}
|
||||
|
||||
/** 启动时显示主页 */
|
||||
@@ -97,6 +107,8 @@ export class MissionHomeComp extends CCComp {
|
||||
}
|
||||
|
||||
onEnable() {
|
||||
// 节点重新激活时补刷一次红点(事件分发期间本节点可能处于隐藏态)
|
||||
this.refreshRedDots()
|
||||
}
|
||||
|
||||
update(dt: number) {
|
||||
@@ -233,6 +245,32 @@ export class MissionHomeComp extends CCComp {
|
||||
if (child) child.active = active
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新页签按钮红点:
|
||||
* - hero_btn/red_dot:任意英雄碎片满足升级条件(canHeroUpgrade)时显示
|
||||
* - tals_btn/red_dot:存在未分配的天赋点(talent_points > 0)时显示
|
||||
*/
|
||||
private refreshRedDots() {
|
||||
this.setRedDot(this.hero_btn, this.hasUpgradableHero())
|
||||
this.setRedDot(this.tals_btn, smc.getTalentPoints() > 0)
|
||||
}
|
||||
|
||||
/** 遍历全量英雄,判定是否存在可升级者(未满级且碎片充足) */
|
||||
private hasUpgradableHero(): boolean {
|
||||
for (const uuid of HeroList) {
|
||||
const growth = smc.getHeroGrowth(uuid);
|
||||
if (canHeroUpgrade(growth.lv, growth.fragments)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 切换按钮下 red_dot 子节点的显示 */
|
||||
private setRedDot(btn: Node, active: boolean) {
|
||||
if (!btn || !btn.isValid) return
|
||||
const dot = btn.getChildByName("red_dot")
|
||||
if (dot) dot.active = active
|
||||
}
|
||||
|
||||
openRanks() {
|
||||
this.showPage(this.ranks_page)
|
||||
}
|
||||
@@ -254,6 +292,7 @@ export class MissionHomeComp extends CCComp {
|
||||
this.stopStartGuide();
|
||||
this.uodate_data()
|
||||
this.hideAllPages()
|
||||
this.refreshRedDots()
|
||||
this.node.active = true
|
||||
// 播放主页背景音乐,恢复默认音量
|
||||
oops.audio.volumeMusic = 1.0;
|
||||
|
||||
Reference in New Issue
Block a user