Files
pixelheros/assets/script/game/map/MissionHomeComp.ts
panFD 7dd5257fd8 修复(地图任务组件): 调整战斗和主页场景的背景音乐音量
为战斗场景设置背景音乐音量为0.5,为主页场景恢复默认音量1.0,同时更新对应注释说明。
2026-06-13 11:23:30 +08:00

182 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file MissionHomeComp.ts
* @description 任务主页组件UI 视图层)
*
* 职责:
* 1. 作为玩家进入游戏后第一个看到的界面(主菜单/大厅)。
* 2. 提供"开始任务"按钮,触发 GameEvent.MissionStart 进入战斗。
* 3. 提供"排行榜"按钮,打开 RanksComp 弹窗。
* 4. 监听 MissionEnd 事件,任务结束后自动切回主页。
*
* 关键设计:
* - start_mission() 分发 MissionStart 事件并隐藏自身节点。
* - mission_end() 响应后重新显示主页。
* - isWxClient() 检测是否运行在微信小游戏环境。
*
* 依赖:
* - GameEvent.MissionStart / MissionEnd —— 游戏生命周期事件
* - UIID.Mission —— 战斗界面 ID
*/
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";
import { smc } from "../common/SingletonModuleComp";
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";
const { ccclass, property } = _decorator;
/**
* MissionHomeComp —— 任务主页视图组件
*
* 游戏大厅界面,提供开始战斗和查看排行的入口。
*/
@ccclass('MissionHomeComp')
@ecs.register('MissionHome', false)
export class MissionHomeComp extends CCComp {
/** 调试日志开关 */
debugMode: boolean = false;
/** 主页按钮节点(预留) */
@property(Node)
home_btn=null!
/** 英雄图鉴按钮节点(预留) */
@property(Node)
hero_btn=null!
/** 排行榜按钮节点 */
@property(Node)
rank_btn=null!
/** 天赋按钮节点 */
@property(Node)
tals_btn=null!
@property(Node)
heros_page=null!
@property(Node)
talents_page=null!
@property(Node)
ranks_page=null!
/** 注册任务结束事件 */
protected onLoad(): void {
this.on(GameEvent.MissionEnd,this.mission_end,this)
}
/** 启动时显示主页 */
start() {
this.home_active()
// 首次打开游戏打开guide1
if (!smc.finish_guides.includes(1)) {
oops.gui.open(UIID.Guide1);
}
}
onEnable(){
}
update(dt:number){
}
/**
* 开始任务:
* 1. 打印日志。
* 2. 分发 MissionStart 事件,驱动 MissionComp / MissionCardComp 初始化战斗。
* 3. 隐藏主页节点。
* 4. 隐藏 mapLayer 下的 main 节点。
*/
start_mission() {
mLogger.log(this.debugMode, 'MissionHomeComp', "start_mission")
// 进入战斗后关闭guide1
if (!smc.finish_guides.includes(1)) {
smc.finish_guides.push(1);
oops.gui.remove(UIID.Guide1);
}
oops.gui.open(UIID.Mission)
this.node.active=false;
// 隐藏 mapLayer 下的 main 节点
}
private showPage(page: Node) {
this.heros_page.active = (page === this.heros_page)
this.talents_page.active = (page === this.talents_page)
this.ranks_page.active = (page === this.ranks_page)
this.setBarActive(this.hero_btn, page === this.heros_page)
this.setBarActive(this.tals_btn, page === this.talents_page)
this.setBarActive(this.rank_btn, page === this.ranks_page)
this.setBarActive(this.home_btn, false)
}
private hideAllPages() {
this.heros_page.active = false
this.talents_page.active = false
this.ranks_page.active = false
this.setBarActive(this.home_btn, true)
this.setBarActive(this.hero_btn, false)
this.setBarActive(this.tals_btn, false)
this.setBarActive(this.rank_btn, false)
}
private setBarActive(btn: Node, active: boolean) {
if (!btn) return
const child = btn.getChildByName("active")
if (child) child.active = active
}
openRanks() {
this.showPage(this.ranks_page)
}
openHero() {
this.showPage(this.heros_page)
}
openTalents() {
this.showPage(this.talents_page)
}
/** 任务结束回调:重新显示主页 */
mission_end(){
mLogger.log(this.debugMode, 'MissionHomeComp', "[MissionHomeComp]=>mission_end")
this.home_active()
}
/** 激活主页显示:刷新数据并显示节点 */
home_active(){
this.uodate_data()
this.hideAllPages()
this.node.active=true
// 播放主页背景音乐,恢复默认音量
oops.audio.volumeMusic = 1.0;
oops.audio.playerMusicLoop("music/home")
}
/** 更新主页显示数据(预留) */
uodate_data(){
}
/**
* 判断是否运行在微信小游戏环境。
* @returns true = 微信小游戏环境
*/
isWxClient(){
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
}
/** ECS 组件移除时销毁节点 */
reset() {
this.node.destroy();
}
}