4 Commits

Author SHA1 Message Date
panw
64536e926f fix: 修复英雄列表导航循环和节点查找逻辑
- 将前后导航改为循环切换,避免边界条件导致的无法切换
- 统一使用 findNodeByName 方法查找节点,解决大小写不一致导致的节点查找失败
- 添加 HeroList 空数组检查,防止运行时错误
2026-04-01 16:43:11 +08:00
panw
61b45c2dd9 feat(角色界面): 实现英雄列表浏览与技能展示功能
- 在 heroSet.ts 中添加 HeroList 数组,定义可浏览的英雄 ID 列表
- 激活角色控制器界面中的相关节点以启用功能
- 重构 HlistComp 组件,添加英雄列表翻页、属性显示、动画加载和技能信息展示逻辑
- 通过 HeroList 数组顺序浏览英雄,并展示其名称、攻击力、生命值、技能详情和类型图标
2026-04-01 16:30:55 +08:00
panw
b92d5d931d feat(任务主页): 增加标签页切换功能
在 home_active 方法中调用 switch_tab 以默认激活首页标签
重构 btn_func 方法,根据传入参数切换不同标签页
新增 switch_tab 方法,统一管理标签页与对应按钮的激活状态
2026-04-01 16:15:32 +08:00
panw
ed0d08b804 feat(地图): 新增英雄列表组件并扩展主页组件属性
- 添加 HlistComp 组件用于展示英雄列表,包含英雄图标、属性显示及翻页按钮
- 在 MissionHomeComp 中增加页面节点和按钮的引用属性,为页面切换功能做准备
2026-04-01 16:15:19 +08:00
5 changed files with 2132 additions and 1812 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -186,5 +186,12 @@ export const HeroInfo: Record<number, heroInfo> = {
};
export const HeroList: number[] = [
5001, 5002, 5003, 5004, 5005,
5101, 5102, 5103, 5104, 5105,
5201, 5202, 5203,
5301, 5302, 5303, 5304
];

View File

@@ -0,0 +1,177 @@
import { _decorator, Animation, AnimationClip, Button, Event, Label, Node, NodeEventType, Sprite, resources } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroInfo, HeroList } from "../common/config/heroSet";
import { IType, SkillSet } from "../common/config/SkillSet";
import { oops } from "db://oops-framework/core/Oops";
import { mLogger } from "../common/Logger";
const {property, ccclass } = _decorator;
/** 视图层对象 */
@ccclass('HListComp')
@ecs.register('HListComp', false)
export class HListComp extends CCComp {
@property(Node)
hero_icon=null!
@property(Node)
ap_node=null!
@property(Node)
hp_node=null!
@property(Node)
info_node=null!
@property(Node)
name_node=null!
@property(Node)
pre_btn=null!
@property(Node)
next_btn=null!
huuid:number=null!
private currentIndex: number = 0;
private iconVisualToken: number = 0;
debugMode: boolean = false;
onLoad() {
this.pre_btn?.on(NodeEventType.TOUCH_END, this.onPreClick, this);
this.next_btn?.on(NodeEventType.TOUCH_END, this.onNextClick, this);
}
start() {
if (HeroList && HeroList.length > 0) {
this.currentIndex = 0;
this.updateHeroView();
}
}
private onPreClick() {
if (!HeroList || HeroList.length === 0) return;
this.currentIndex = (this.currentIndex - 1 + HeroList.length) % HeroList.length;
this.updateHeroView();
}
private onNextClick() {
if (!HeroList || HeroList.length === 0) return;
this.currentIndex = (this.currentIndex + 1) % HeroList.length;
this.updateHeroView();
}
private updateHeroView() {
this.huuid = HeroList[this.currentIndex];
const hero = HeroInfo[this.huuid];
if (!hero) return;
// 更新基础属性标签
this.setLabelText(this.name_node, hero.name);
this.setLabelText(this.ap_node, `攻击力: ${hero.ap}`);
this.setLabelText(this.hp_node, `生命值: ${hero.hp}`);
// 更新动画
this.updateHeroAnimation(this.hero_icon, this.huuid);
// 更新技能列表
this.updateSkillInfo(hero);
}
private setLabelText(node: Node, text: string) {
if (!node) return;
const label = node.getComponent(Label) || node.getComponentInChildren(Label);
if (label) {
label.string = text;
}
}
private updateHeroAnimation(node: Node, uuid: number) {
if (!node) return;
const sprite = node.getComponent(Sprite) || node.getComponentInChildren(Sprite);
if (sprite) sprite.spriteFrame = null;
const hero = HeroInfo[uuid];
if (!hero) return;
const anim = node.getComponent(Animation) || node.addComponent(Animation);
this.clearAnimationClips(anim);
this.iconVisualToken++;
const token = this.iconVisualToken;
const path = `game/heros/hero/${hero.path}/idle`;
resources.load(path, AnimationClip, (err, clip) => {
if (err || !clip) {
mLogger.log(this.debugMode, "HListComp", `load hero animation failed ${uuid}`, err);
return;
}
if (token !== this.iconVisualToken || this.huuid !== uuid) {
return;
}
this.clearAnimationClips(anim);
anim.addClip(clip);
anim.play("idle");
});
}
private clearAnimationClips(anim: Animation) {
const clips = anim.clips;
if (clips && clips.length > 0) {
for (let i = clips.length - 1; i >= 0; i--) {
const clip = clips[i];
if (clip) anim.removeClip(clip, true);
}
}
}
private findNodeByName(root: Node, name: string): Node | null {
if (!root) return null;
if (root.name === name) return root;
for (let i = 0; i < root.children.length; i++) {
const res = this.findNodeByName(root.children[i], name);
if (res) return res;
}
return null;
}
private updateSkillInfo(hero: any) {
if (!this.info_node) return;
const skills = Object.values(hero.skills || {});
for (let i = 1; i <= 5; i++) {
let line = this.findNodeByName(this.info_node, `Line${i}`) || this.findNodeByName(this.info_node, `line${i}`);
if (!line) continue;
const skill: any = skills[i - 1];
if (skill) {
line.active = true;
const skillId = skill.uuid;
const config = SkillSet[skillId];
const text = config ? `${config.name} Lv.${skill.lv} CD:${skill.cd}s ${config.info}` : `未知技能 CD:${skill.cd}s`;
const noteNode = this.findNodeByName(line, "note");
const label = noteNode?.getComponent(Label) || noteNode?.getComponentInChildren(Label) || line.getComponentInChildren(Label);
if (label) {
label.string = text;
}
this.updateLineTypeIcon(line, config?.IType);
} else {
line.active = false;
}
}
}
private updateLineTypeIcon(line: Node, iType?: IType) {
const meleeNode = this.findNodeByName(line, "Melee");
const remoteNode = this.findNodeByName(line, "remote");
const supportNode = this.findNodeByName(line, "support");
if (meleeNode) meleeNode.active = iType === IType.Melee;
if (remoteNode) remoteNode.active = iType === IType.remote;
if (supportNode) supportNode.active = iType === IType.support;
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"89bf6d65-5432-4946-9b14-3e5150dddedd","files":[],"subMetas":{},"userData":{}}

View File

@@ -1,4 +1,4 @@
import { _decorator, instantiate, Prefab, resources, Sprite, SpriteAtlas, UITransform } from "cc";
import { _decorator, instantiate, Prefab, resources, Sprite, SpriteAtlas, UITransform ,Node} from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
@@ -15,6 +15,19 @@ const { ccclass, property } = _decorator;
export class MissionHomeComp extends CCComp {
debugMode: boolean = false;
@property(Node)
heros_page=null!
@property(Node)
rank_page=null!
@property(Node)
home_btn=null!
@property(Node)
hero_btn=null!
@property(Node)
rank_btn=null!
protected onLoad(): void {
this.on(GameEvent.MissionEnd,this.mission_end,this)
}
@@ -42,7 +55,7 @@ export class MissionHomeComp extends CCComp {
home_active(){
this.uodate_data()
this.node.active=true
this.switch_tab('home')
}
uodate_data(){
@@ -50,8 +63,24 @@ export class MissionHomeComp extends CCComp {
isWxClient(){
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
}
btn_func(e:string,data:any){
btn_func(e: any, data: string){
if (['home', 'hero', 'rank'].includes(data)) {
this.switch_tab(data);
}
}
switch_tab(tab: string) {
if (this.heros_page) this.heros_page.active = tab === 'hero';
if (this.rank_page) this.rank_page.active = tab === 'rank';
const setBtnActive = (btn: Node, isActive: boolean) => {
const activeNode = btn?.getChildByName('active');
if (activeNode) activeNode.active = isActive;
}
setBtnActive(this.home_btn, tab === 'home');
setBtnActive(this.hero_btn, tab === 'hero');
setBtnActive(this.rank_btn, tab === 'rank');
}