技能设置清理

This commit is contained in:
2025-10-16 11:14:28 +08:00
parent 7ec02c4b9e
commit 31eedceeb3
39 changed files with 812 additions and 2752 deletions

View File

@@ -1,168 +0,0 @@
import { _decorator, Component, Node, Label, Sprite, SpriteFrame, resources } from 'cc';
import { Goods, GType, CType } from '../common/config/Goods';
import { Items } from '../common/config/Items';
import { NumberFormatter } from '../common/config/BoxSet';
import { smc } from '../common/SingletonModuleComp';
import { oops } from 'db://oops-framework/core/Oops';
const { ccclass, property } = _decorator;
@ccclass('GoodsComp')
export class GoodsComp extends Component {
// 数据(仅用于更新显示)
private goodsData: any = null;
private itemData: any = null;
private currentUuid: number = 0;
goods_count_key:number=-1
/**
* 更新物品数据
* @param uuid 物品UUID
*/
update_data(uuid: number,key:number) {
this.goods_count_key=key
this.currentUuid = uuid;
this.goodsData = Goods[uuid];
if (!this.goodsData) {
console.error(`Goods data not found for uuid: ${uuid}`);
return;
}
this.itemData = Items[this.goodsData.i_uuid];
if (!this.itemData) {
console.error(`Item data not found for i_uuid: ${this.goodsData.i_uuid}`);
return;
}
this.updateIcon();
this.updateTexts();
this.update_btn()
this.update_max_num()
}
private update_btn( ){
if(smc.shop.goods_count[this.goods_count_key]<=0){
this.node.getChildByName("btn").getChildByName("ad").active=false
this.node.getChildByName("btn").getChildByName("free").active=false
this.node.getChildByName("btn").getChildByName("diamond").active=false
this.node.getChildByName("btn").getChildByName("gold").active=false
this.node.getChildByName("btn").getChildByName("nothing").active=true
this.node.getChildByName("btn").getComponent(Sprite).grayscale=true
return
}
this.node.getChildByName("btn").getChildByName("nothing").active=false
this.node.getChildByName("btn").getComponent(Sprite).grayscale=false
this.node.getChildByName("btn").getChildByName("ad").active=this.goodsData.c_type==CType.AD
this.node.getChildByName("btn").getChildByName("free").active=this.goodsData.c_type==CType.FREE
this.node.getChildByName("btn").getChildByName("diamond").getChildByName("num").getComponent(Label).string=NumberFormatter.formatNumber(this.goodsData.cast)
this.node.getChildByName("btn").getChildByName("gold").getChildByName("num").getComponent(Label).string=NumberFormatter.formatNumber(this.goodsData.cast)
this.node.getChildByName("btn").getChildByName("diamond").active=this.goodsData.c_type==CType.DIAMOND
this.node.getChildByName("btn").getChildByName("gold").active=this.goodsData.c_type==CType.GOLD
}
/**
* 更新图标
*/
private update_max_num(){
this.node.getChildByName("max").getComponent(Label).string=NumberFormatter.formatNumber(smc.shop.goods_count[this.goods_count_key])
}
private updateIcon() {
const iconSprite = this.node.getChildByName("icon")?.getComponent(Sprite);
if (!iconSprite) return;
const path = `gui/items/${this.itemData.path}`;
resources.load(path, SpriteFrame, (err, spriteFrame) => {
if (err) {
console.warn(`icon load failed: ${path}`, err);
return;
}
iconSprite.spriteFrame = spriteFrame;
});
}
/** 仅更新文字(名称与数量) */
private updateTexts() {
// 名称
const nameLabel = this.node.getChildByName("name")?.getComponent(Label);
if (nameLabel) nameLabel.string = this.itemData.name;
// 数量(根节点下的 num
const mainNumLabel = this.node.getChildByName("num")?.getComponent(Label);
if (mainNumLabel) mainNumLabel.string = NumberFormatter.formatNumber(this.goodsData.num);
}
to_buy(){
if(smc.shop.goods_count[this.goods_count_key]<=0){
oops.gui.toast("商品已售罄")
return
}
if(this.goodsData.c_type==CType.AD){
this.do_ad()
}else if(this.goodsData.c_type==CType.FREE){
this.do_free()
}else if(this.goodsData.c_type==CType.DIAMOND){
if(smc.data.diamond<this.goodsData.cast){
oops.gui.toast("钻石不足")
return
}
this.do_diamond_cast()
}else if(this.goodsData.c_type==CType.GOLD){
if(smc.data.gold<this.goodsData.cast){
oops.gui.toast("金币不足")
return
}
this.do_gold_cast()
}
}
do_buy(){
// console.log("[GoodsComp]do_buy",this.goodsData,this.itemData)
switch(this.goodsData.type){
case GType.ITEM:
smc.addItem(this.itemData.uuid,this.goodsData.num) //添加物品
break
case GType.GOLD:
smc.addGold(this.goodsData.num) //添加金币
break
case GType.DIAMOND:
smc.addDiamond(this.goodsData.num) //添加钻石
break
case GType.MEAT: //添加肉
break
case GType.EXP: //添加经验
smc.addExp(this.goodsData.num)
break
}
smc.shop.goods_count[this.goods_count_key]--
this.update_btn()
this.update_max_num()
}
do_ad(){
if(this.goodsData.c_type==CType.AD){
this.do_ad_back(this.do_buy,this.ad_back_false)
}
}
ad_back_false(){
// console.log("ad_back_false")
}
do_ad_back(success:Function,fail:Function){
success.call(this)
}
do_free(){
if(this.goodsData.c_type==CType.FREE){
this.do_buy()
}
}
do_diamond_cast(){
if(this.goodsData.c_type==CType.DIAMOND){
smc.spendDiamond(this.goodsData.cast)
this.do_buy()
}
}
do_gold_cast(){
if(this.goodsData.c_type==CType.GOLD){
smc.spendGold(this.goodsData.cast)
this.do_buy()
}
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "e24167ce-79d0-4f99-a3d8-f144bbe959a3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,48 +0,0 @@
import { _decorator, Component, instantiate, Node, Prefab, UITransform } from 'cc';
import { smc } from '../common/SingletonModuleComp';
import { oops } from 'db://oops-framework/core/Oops';
import { HeroConSet } from '../common/config/BoxSet';
import { getHeroList } from '../common/config/heroSet';
const { ccclass, property } = _decorator;
@ccclass('HeroPageComp')
export class HeroPageComp extends Component {
start() {
// console.log("[HeroPageComp]:start")
}
update(deltaTime: number) {
}
onEnable(){
this.update_heros()
}
update_heros(){
let heros=getHeroList()
// console.log("[HeroPageComp]:update_heros",heros)
let height= Math.ceil(heros.length/3)*315+30
this.node.getChildByName("main").getChildByName("view").getChildByName("heros").getComponent(UITransform).setContentSize(720,height)
// console.log("[HeroPageComp]:UITransform height",this.node.getChildByName("main").getChildByName("view").getChildByName("heros").getComponent(UITransform))
this.clear_heros()
for(let i=0;i<heros.length;i++){
let hero=heros[i]
if(hero){
this.load_hero(hero)
}
}
}
load_hero(uuid:number){
}
clear_heros(){
let parent=this.node.getChildByName("main").getChildByName("view").getChildByName("heros")
let children=parent.children
// console.log("[HeroPageComp]:clear_heros",children)
for(let i=0;i<children.length;i++){
children[i].destroy()
}
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "985ee2ae-8a25-4d68-a4f3-d909f5b2c225",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,222 +0,0 @@
import { _decorator, Component, Node, Label, Sprite, resources, SpriteFrame } from 'cc';
import { Items } from '../common/config/Items';
import { QualitySet } from '../common/config/BoxSet';
import { oops } from 'db://oops-framework/core/Oops';
import { UIID } from '../common/config/GameUIConfig';
const { ccclass, property } = _decorator;
@ccclass('ItemComp')
export class ItemComp extends Component {
item_uuid: number = 0;
item_count: number = 1;
type: number = 0;
slot: number = 0;
no_show:boolean=false
start() {
// console.log("[ItemComp]:start");
}
update(deltaTime: number) {
}
/**
* 更新物品数据
* @param hero_uuid 物品ID
* @param count 物品数量
* @param args 额外参数
*/
update_data(hero_uuid: number, count: number = 1, args: any = {}) {
this.item_uuid = hero_uuid;
this.item_count = count;
this.type = args.type || 0;
this.slot = args.slot || 0;
this.no_show = args.no_show || false;
// console.log("[ItemComp]:update_data", hero_uuid, count, this.type, this.slot, args);
// 获取物品配置
const itemData = Items[hero_uuid];
if (!itemData) {
console.error("[ItemComp]: Item not found", hero_uuid);
return;
}
// 设置物品图标
this.setItemIcon(itemData.path);
// 设置品质边框
this.setQualityFrame(itemData.quality);
// 设置数量显示
this.setItemCount(count);
// 设置选中状态
if (args.selected) {
this.setSelected(true);
} else {
this.setSelected(false);
}
}
/**
* 设置物品图标
* @param iconPath 图标路径
*/
private setItemIcon(iconPath: string) {
let path=`gui/items/${iconPath}`
// console.log("[ItemComp]: setItemIcon", path);
resources.load(path, SpriteFrame, (err, spriteFrame) => {
if (err) {
console.error("[ItemComp]: Failed to load item icon", iconPath, err);
return;
}
// console.log("[ItemComp]: setItemIcon", iconPath, spriteFrame);
this.node.getChildByName("icon").getComponent(Sprite)!.spriteFrame = spriteFrame;
});
}
/**
* 设置品质边框
* @param quality 品质类型
*/
private setQualityFrame(quality: QualitySet) {
// 隐藏所有品质边框
this.hideAllQualityFrames();
// 根据品质显示对应边框
switch (quality) {
case QualitySet.GREEN:
this.node.getChildByName("q1").active = true;
break;
case QualitySet.BLUE:
this.node.getChildByName("q2").active = true;
break;
case QualitySet.PURPLE:
this.node.getChildByName("q3").active = true;
break;
case QualitySet.ORANGE:
this.node.getChildByName("q4").active = true;
break;
default:
// 默认使用绿色边框
this.node.getChildByName("q").active = true;
break;
}
}
/**
* 隐藏所有品质边框
*/
private hideAllQualityFrames() {
this.node.getChildByName("q").active = false;
this.node.getChildByName("q1").active = false;
this.node.getChildByName("q2").active = false;
this.node.getChildByName("q3").active = false;
this.node.getChildByName("q4").active = false;
this.node.getChildByName("focus").active = false;
}
/**
* 设置物品数量
* @param count 数量
*/
private setItemCount(count: number) {
this.node.getChildByName("num").getComponent(Label)!.string = count.toString();
}
/**
* 设置选中状态
* @param selected 是否选中
*/
private setSelected(selected: boolean) {
this.node.getChildByName("focus").active = selected;
}
/**
* 物品点击事件
*/
do_click() {
// console.log("[ItemComp]: Item clicked", this.item_uuid, this.item_count);
// 根据类型处理不同逻辑
switch (this.type) {
case 1: // 普通点击
this.onItemClick();
break;
case 2: // 选择物品
this.onItemSelect();
break;
case 3: // 使用物品
this.onItemUse();
break;
default:
this.onItemClick();
break;
}
}
/**
* 普通物品点击
*/
private onItemClick() {
// 显示物品信息或执行其他逻辑
// console.log("[ItemComp]: Show item info", this.item_uuid);
}
/**
* 选择物品
*/
private onItemSelect() {
// 处理物品选择逻辑
// console.log("[ItemComp]: Item selected", this.item_uuid);
}
/**
* 使用物品
*/
private onItemUse() {
// 处理物品使用逻辑
// console.log("[ItemComp]: Use item", this.item_uuid);
}
show_item_info(){
if(this.no_show){
return
}
oops.gui.open(UIID.ItemInfo, { item_uuid: this.item_uuid ,count:this.item_count});
}
/**
* 获取物品UUID
*/
getItemUUID(): number {
return this.item_uuid;
}
/**
* 获取物品数量
*/
getItemCount(): number {
return this.item_count;
}
addItemCount(count:number){
this.item_count+=count
this.setItemCount(this.item_count)
}
/**
* 设置物品类型
*/
setItemType(type: number) {
this.type = type;
}
/**
* 设置物品槽位
*/
setItemSlot(slot: number) {
this.slot = slot;
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "691f8376-3937-42db-ae4b-771d4cc67b25",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,50 +0,0 @@
import { _decorator, Animation, Component, Label, Node, resources, Sprite, SpriteAtlas, tween, v3 } from 'cc';
import { SuperCards, SuperCardsType } from '../common/config/CardSet';
import { SkillSet } from '../common/config/SkillSet';
const { ccclass, property } = _decorator;
@ccclass('LuckCardComp')
export class LuckCardComp extends Component {
timer:number=3;
start() {
this.timer=2
// console.log("[LuckCardComp]:start")
}
update(deltaTime: number) {
this.timer-=deltaTime
if(this.timer<=0){
let anim=this.node.getComponent(Animation)
if(anim) anim.play("luckcardend")
this.do_destroy()
this.timer=2
}
}
show_card(card:any){
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(SuperCards[card.uuid].path);
});
this.node.getChildByName("name").getComponent(Label).string=SuperCards[card.uuid].name
switch(SuperCards[card.uuid].type){
case SuperCardsType.BUFF:
this.node.getChildByName("val").getComponent(Label).string="+"+SuperCards[card.uuid].value2
break
case SuperCardsType.AOE:
this.node.getChildByName("val").getComponent(Label).string=SkillSet[SuperCards[card.uuid].value1].name+"X"+SuperCards[card.uuid].value2
break
}
}
do_destroy(){
tween(this.node)
.to(0.2, {
scale: v3(2,2,0),
}, {onComplete:()=>{
this.node.destroy()
}})
.start();
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "598155fc-f31b-4496-b1e4-82219435f425",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,131 +0,0 @@
import { _decorator, resources, Sprite, SpriteAtlas ,Node, ProgressBar, tween, v3, Label, Animation, CCString, CCInteger} 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 { GameEvent } from "../common/config/GameEvent";
import { CdType, SkillSet } from "../common/config/SkillSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "db://oops-framework/core/Oops";
import { MissionEvent } from "../common/config/MissionEvent";
import { HeroInfo } from "../common/config/heroSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('MSkillComp')
@ecs.register('MSkill', false)
export class MSkillComp extends CCComp {
@property(CCString)
skill_slot:string="skill1"
@property(CCInteger)
skill_slot_index:number=1
skill:any=null
skill_cd_bar_progress:any=null
max_show:boolean=false
/** 视图层逻辑代码分离演示 */
onLoad() {
this.on(GameEvent.UseSkillCard, this.get_skill, this);
this.on(GameEvent.FightReady,this.fight_ready,this)
this.on(GameEvent.MasterCalled,this.master_called,this)
// this.node.getChildByName("icon").getChildByName("cd").active=false
}
start(){
this.fight_ready()
}
private master_called(e:any,data:any){
// console.log("[EquipSkillComp]: master_called",data)
let hero=HeroInfo[data.uuid]
if(hero.skills.length>0){
this.get_skill(null,{slot:this.skill_slot,uuid:hero.skills[this.skill_slot_index]})
}
}
fight_ready(){
// console.log("[MSkillComp]: fight_ready",this.node)
this.node.getChildByName("icon").active=false
this.hide_skill_get(null,"skill1")
this.skill={
uuid:0,
name:"skill1",
type:0, //1 被动 0 主动
level:0,
quality:0,
cd:0,
cd_time:0,
active:false,
}
}
update(dt: number): void {
if(!smc.mission.play||smc.mission.pause) return
}
show_max(){
this.node.getChildByName("light").active=true
this.node.getComponent(Animation).play()
}
hide_max(){
this.max_show=false
this.node.getChildByName("light").active=false
this.node.setScale(1,1,1)
this.node.getComponent(Animation).stop()
}
spell_skill(){
// console.log("spell_skill")
this.skill.cd_time=0
tween(this.node).to(0.1, {scale:v3(1.2,1.2,1)},{onComplete:()=>{
tween(this.node).to(0.2, {scale:v3(1,1,1)}).start()
}}).start()
this.do_skill(this.skill.uuid)
this.hide_max()
}
do_skill(uuid:number){
oops.message.dispatchEvent(GameEvent.CastHeroSkill,uuid)
}
get_skill(e:GameEvent,data:any){
// console.log("[MSkillComp]: get_skill",data)
if(data.slot==this.skill_slot||this.skill_slot_index==data.slot){
this.skill.uuid=data.uuid
this.skill.skill_name=SkillSet[data.uuid].name
this.skill.type=1
this.skill.cd=SkillSet[data.uuid].cd
this.skill.cd_time=SkillSet[data.uuid].cd
let icon1 = this.node.getChildByName("icon")
icon1.active=true
// if(SkillSet[data.uuid].CdType!=CdType.cd){
// icon1.getChildByName("cd").active=false
// }
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = icon1.getChildByName("skill").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
});
}
}
call_skill_card(e:any,data:any){
oops.message.dispatchEvent(GameEvent.HeroSkillSelect,{slot:data})
}
show_info(e:any,data:any){
// console.log("[MSkillComp]: show_info",this.skill)
}
private hide_skill_get(e:any,data:string){
this.node.getChildByName("get").active =false
this.node.getChildByName("tip").active =false
this.node.getChildByName("light").active=false
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "e0acc008-a00f-4682-ba4f-c47506bddf26",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,40 +0,0 @@
import { _decorator, Component, Node } from 'cc';
import { GoodsComp } from './GoodsComp';
import { smc } from '../common/SingletonModuleComp';
import { getRandomGoods } from '../common/config/Goods';
const { ccclass, property } = _decorator;
@ccclass('ShopPageComp')
export class ShopPageComp extends Component {
daily:any[]=[]
weekly:any[]=[]
monthly:any[]=[]
special:any[]=[]
start() {
this.update_daily()
this.update_weekly()
}
update_daily(){
let items=this.node.getChildByName("daily").getChildByName("items").children
for(let i=0;i<items.length;i++){
let goods=items[i]
goods.getComponent(GoodsComp).update_data(smc.shop.daily[i],i)
}
}
update_weekly(){
if(smc.shop.weekly.length ==0) {
this.weekly=getRandomGoods()
}
smc.shop.weekly=this.weekly
let items=this.node.getChildByName("weekly").getChildByName("items").children
for(let i=0;i<items.length;i++){
let goods=items[i]
goods.getComponent(GoodsComp).update_data(smc.shop.weekly[i],i+4)
}
}
update(deltaTime: number) {
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "6e8e04b0-e0eb-4668-8543-30322e2c359f",
"files": [],
"subMetas": {},
"userData": {}
}