奖励已经双倍奖励

This commit is contained in:
2025-08-19 19:40:34 +08:00
parent 22f35893d7
commit 854affeaae
32 changed files with 12848 additions and 7746 deletions

View File

@@ -0,0 +1,222 @@
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;
}
}