refactor(heroUi): 精简和优化英雄界面预制资源
heriui载入 还有问题 - 移除了大量冗余节点和组件,减小预制体体积 - 调整部分节点名称和层级结构,更加清晰易维护 - 优化部分节点位置和尺寸属性,提升界面表现一致性 - 更新部分精灵资源引用及颜色配置,保证视觉效果正确 - 删除无用的动画剪辑和挂载组件,提升加载性能 - 重新整理属性覆盖信息,保持配置整洁规范
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { _decorator, Animation, AnimationClip, CCInteger, Component, Label, Node, resources } from 'cc';
|
||||
import { _decorator, Animation, AnimationClip, CCInteger, Component, instantiate, Label, Node, Prefab, resources, v3 } from 'cc';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { HeroInfo } from '../common/config/heroSet';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
@@ -12,66 +12,39 @@ const { ccclass, property } = _decorator;
|
||||
export class HeroReadyCom extends Component {
|
||||
@property(CCInteger)
|
||||
slot: number=0;
|
||||
@property(Prefab)
|
||||
hero_prefab: Prefab = null!;
|
||||
protected onLoad(): void {
|
||||
oops.message.on(GameEvent.UpdateHero,this.update_hero,this)
|
||||
oops.message.on(GameEvent.UpdateFightHero,this.update_hero,this)
|
||||
oops.message.on(GameEvent.HeroSpeek,this.to_speek,this)
|
||||
|
||||
}
|
||||
start() {
|
||||
this.hide_speek()
|
||||
this.update_hero()
|
||||
|
||||
}
|
||||
hide_speek(){
|
||||
this.node.getChildByName("tooltip").active=false
|
||||
}
|
||||
to_speek(e:any,args:any){
|
||||
console.log("[HeroReadyCom]:to_speek",args,this.slot)
|
||||
if(args.slot!=this.slot) return
|
||||
if(smc.fight_heros[this.slot]==0) return
|
||||
this.node.getChildByName("tooltip").active=true
|
||||
this.node.getChildByName("tooltip").getChildByName("words").getComponent(Label)!.string = args.words
|
||||
this.scheduleOnce(()=>{
|
||||
this.hide_speek()
|
||||
},3)
|
||||
this.add_heros()
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
update_hero(){
|
||||
let hero = smc.fight_heros[this.slot]
|
||||
// console.log("[HeroReadyCom]hero",hero,smc.fight_heros,this.slot)
|
||||
if(hero==0){
|
||||
this.no_hero()
|
||||
return
|
||||
add_heros(){
|
||||
let heros=smc.heros
|
||||
let x=0
|
||||
for(let key in heros){
|
||||
this.add_hero(heros[key].uuid,x)
|
||||
console.log("[HeroReadyCom]:add_hero",heros[key],x)
|
||||
x++
|
||||
}
|
||||
this.node.getChildByName("icon").active=true
|
||||
this.node.getChildByName("add").active=false
|
||||
}
|
||||
add_hero(hero:any,pos:number){
|
||||
let hero_data = HeroInfo[hero]
|
||||
// console.log("[HeroReadyCom]hero_data",smc.fight_heros,hero,smc.fight_heros[this.slot],this.slot,hero_data)
|
||||
if(!this.hero_prefab) return
|
||||
const node = instantiate(this.hero_prefab) as unknown as Node;
|
||||
let anm_path=hero_data.path
|
||||
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
|
||||
this.node.getChildByName("icon").getComponent(Animation).addClip(clip);
|
||||
this.node.getChildByName("icon").getComponent(Animation).play("idle");
|
||||
node.getChildByName("hero").getComponent(Animation).addClip(clip);
|
||||
node.getChildByName("hero").getComponent(Animation).play("idle");
|
||||
});
|
||||
this.node.getChildByName("lv").active=true
|
||||
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=smc.heros[hero].lv.toString()
|
||||
// console.log("[HeroReadyCom]clip",this.node.getChildByName("icon").getComponent(Animation))
|
||||
|
||||
node.parent = this.node;
|
||||
node.setPosition(v3(-pos*100,0,0))
|
||||
}
|
||||
|
||||
no_hero(){
|
||||
this.node.getChildByName("lv").active=false
|
||||
this.node.getChildByName("add").active=true
|
||||
this.node.getChildByName("icon").active=false
|
||||
}
|
||||
select_hero(){
|
||||
if(oops.gui.has(UIID.HeroSelect)) return
|
||||
if(smc.fight_heros[this.slot]==0) {
|
||||
finishCurrGuide(8)
|
||||
}
|
||||
oops.gui.open(UIID.HeroSelect,{slot:this.slot})
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy()
|
||||
}
|
||||
|
||||
@@ -52,70 +52,12 @@ export class MissionComp extends CCComp {
|
||||
}
|
||||
do_drop(drop_item:any[],game_data:any={exp:0,gold:0,diamond:0}){
|
||||
// console.log("[MissionComp] do_drop",drop_item,game_data)
|
||||
this.game_data["exp"]+=game_data.exp
|
||||
this.game_data["gold"]+=game_data.gold
|
||||
this.game_data["diamond"]+=game_data.diamond
|
||||
let parent=this.node.getChildByName("reward").getChildByName("items")
|
||||
let items=parent.children
|
||||
if(drop_item.length>0){
|
||||
for(let i=0;i<drop_item.length;i++){
|
||||
let d_item=drop_item[i]
|
||||
// 查找是否已存在该物品
|
||||
const existingItem = this.rewards.find(item => item.item_uuid === d_item.item_uuid);
|
||||
if(existingItem){
|
||||
// 如果已存在该物品,累加数量
|
||||
existingItem.count += d_item.count;
|
||||
}else{
|
||||
// 如果不存在该物品,添加新物品
|
||||
this.rewards.push({item_uuid: d_item.item_uuid, count: d_item.count});
|
||||
}
|
||||
}
|
||||
}
|
||||
for(let i=0;i<items.length;i++){
|
||||
let hitem=items[i].getComponent(ItemComp)
|
||||
for(let j=0;j<drop_item.length;j++){
|
||||
let d_item=drop_item[j]
|
||||
if(d_item.item_uuid==hitem.item_uuid){
|
||||
hitem.addItemCount(d_item.count)
|
||||
drop_item.splice(j,1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if(drop_item.length>0){
|
||||
// console.log("[MissionComp] do_drop 剩余物品",drop_item)
|
||||
for(let i=0;i<drop_item.length;i++){
|
||||
let d_item=drop_item[i]
|
||||
let path="game/gui/item"
|
||||
const prefab = oops.res.get(path, Prefab);
|
||||
if (!prefab) {
|
||||
console.error("[MissionComp=>do_drop] 预制体加载失败:", path);
|
||||
return;
|
||||
}
|
||||
const node = instantiate(prefab) as unknown as Node;
|
||||
node.parent=parent
|
||||
node.getComponent(ItemComp)!.update_data(d_item.item_uuid,d_item.count)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
do_mon_dead(event:any,data:any){
|
||||
// console.log("[MissionComp] do_mon_dead",event,data)
|
||||
smc.vmdata.mission_data.mon_num--
|
||||
if(data.drops){
|
||||
if(data.drops.length>0){
|
||||
this.do_drop(data.drops,data.game_data)
|
||||
}
|
||||
}
|
||||
if(smc.vmdata.mission_data.mon_num<=0) {
|
||||
smc.vmdata.mission_data.level++
|
||||
if(smc.vmdata.mission_data.level < smc.vmdata.mission_data.max_mission){
|
||||
oops.message.dispatchEvent(GameEvent.NewWave)
|
||||
return
|
||||
}
|
||||
smc.addMission(1)
|
||||
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:true})
|
||||
oops.gui.open(UIID.Victory,{victory:true,rewards:this.rewards,game_data:this.game_data})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
do_hero_dead(event:any,data:any){
|
||||
@@ -194,7 +136,6 @@ export class MissionComp extends CCComp {
|
||||
smc.vmdata.mission_data.fight_time=0
|
||||
smc.vmdata.mission_data.level=0
|
||||
this.rewards=[] // 改为数组,用于存储掉落物品列表
|
||||
this.node.getChildByName("reward").getChildByName("items").removeAllChildren()
|
||||
// console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,12 +48,13 @@ export class MissionHeroCompComp extends CCComp {
|
||||
smc.vmdata.mission_data.hero_num=0
|
||||
// console.log("[MissionHeroComp]:fight_ready",smc.fight_heros,Object.keys(smc.fight_heros).length)
|
||||
let heros:any = smc.fight_heros
|
||||
for(let i=0;i<Object.keys(heros).length;i++){
|
||||
if(heros[i]!=0){
|
||||
// console.log("[MissionHeroComp]:fight_ready",heros[i])
|
||||
this.addHero(heros[i],false)
|
||||
}
|
||||
}
|
||||
this.addHero(heros[0],false)
|
||||
// for(let i=0;i<Object.keys(heros).length;i++){
|
||||
// if(heros[i]!=0){
|
||||
// // console.log("[MissionHeroComp]:fight_ready",heros[i])
|
||||
// this.addHero(heros[i],false)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
protected update(dt: number): void {
|
||||
if(smc.mission.status != 1) return
|
||||
|
||||
@@ -69,50 +69,50 @@ export class MissionHomeComp extends CCComp {
|
||||
}
|
||||
btn_func(e:string,data:any){
|
||||
|
||||
// console.log("[MissionHomeComp]:btn_func",e,data)
|
||||
let page_heros=this.node.getChildByName("heros_page")
|
||||
let page_shop=this.node.getChildByName("shop_page")
|
||||
// let page_fight=this.node.getChildByName("fight_page")
|
||||
// let page_skill=this.node.getChildByName("skill_page")
|
||||
// let page_set=this.node.getChildByName("set_page")
|
||||
let btns=this.node.getChildByName("btns")
|
||||
let btn_shop =btns.getChildByName("shop")
|
||||
let btn_heros =btns.getChildByName("heros")
|
||||
let btn_fight =btns.getChildByName("fight")
|
||||
let btn_skill =btns.getChildByName("skill")
|
||||
let btn_set =btns.getChildByName("set")
|
||||
btn_shop.getChildByName("act").active=false
|
||||
btn_heros.getChildByName("act").active=false
|
||||
btn_fight.getChildByName("act").active=false
|
||||
btn_skill.getChildByName("act").active=false
|
||||
btn_set.getChildByName("act").active=false
|
||||
page_heros.active=false
|
||||
page_shop.active=false
|
||||
switch(data){
|
||||
case "shop":
|
||||
page_shop.active=true
|
||||
btn_shop.getChildByName("act").active=true
|
||||
break
|
||||
case "heros":
|
||||
finishCurrGuide(2)
|
||||
page_heros.active=true
|
||||
btn_heros.getChildByName("act").active=true
|
||||
break
|
||||
case "fight":
|
||||
finishCurrGuide(7)
|
||||
startGuide(8)
|
||||
btn_fight.getChildByName("act").active=true
|
||||
break
|
||||
case "skill":
|
||||
btn_skill.getChildByName("act").active=true
|
||||
break
|
||||
case "set":
|
||||
btn_set.getChildByName("act").active=true
|
||||
break
|
||||
default:
|
||||
btn_fight.getChildByName("act").active=true
|
||||
break
|
||||
}
|
||||
// // console.log("[MissionHomeComp]:btn_func",e,data)
|
||||
// let page_heros=this.node.getChildByName("heros_page")
|
||||
// let page_shop=this.node.getChildByName("shop_page")
|
||||
// // let page_fight=this.node.getChildByName("fight_page")
|
||||
// // let page_skill=this.node.getChildByName("skill_page")
|
||||
// // let page_set=this.node.getChildByName("set_page")
|
||||
// let btns=this.node.getChildByName("btns")
|
||||
// let btn_shop =btns.getChildByName("shop")
|
||||
// let btn_heros =btns.getChildByName("heros")
|
||||
// let btn_fight =btns.getChildByName("fight")
|
||||
// let btn_skill =btns.getChildByName("skill")
|
||||
// let btn_set =btns.getChildByName("set")
|
||||
// btn_shop.getChildByName("act").active=false
|
||||
// btn_heros.getChildByName("act").active=false
|
||||
// btn_fight.getChildByName("act").active=false
|
||||
// btn_skill.getChildByName("act").active=false
|
||||
// btn_set.getChildByName("act").active=false
|
||||
// page_heros.active=false
|
||||
// page_shop.active=false
|
||||
// switch(data){
|
||||
// case "shop":
|
||||
// page_shop.active=true
|
||||
// btn_shop.getChildByName("act").active=true
|
||||
// break
|
||||
// case "heros":
|
||||
// finishCurrGuide(2)
|
||||
// page_heros.active=true
|
||||
// btn_heros.getChildByName("act").active=true
|
||||
// break
|
||||
// case "fight":
|
||||
// finishCurrGuide(7)
|
||||
// startGuide(8)
|
||||
// btn_fight.getChildByName("act").active=true
|
||||
// break
|
||||
// case "skill":
|
||||
// btn_skill.getChildByName("act").active=true
|
||||
// break
|
||||
// case "set":
|
||||
// btn_set.getChildByName("act").active=true
|
||||
// break
|
||||
// default:
|
||||
// btn_fight.getChildByName("act").active=true
|
||||
// break
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user