//********************* // create by 流云 // time: Mon Nov 03 2025 // desc: //********************* import { _decorator, Component, Node , find, tween, v3} from 'cc'; import { Auto_buyItemBox } from './Auto_buyItemBox'; import { itemPic } from '../../com/itemPic'; import { IShopItemData, TableNames } from '../../game/ConfigTableData'; import { ItemNumType, OtherDataType, TaskType } from '../../game/GameData'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { ItemData } from '../../game/ConfigProjectData'; import { UIID } from '../../game/ConfigRes'; import { TargetTaskType } from '../../manager/TargetTaskManager'; const { ccclass, property } = _decorator; @ccclass('UIbuyItemBox') export class UIbuyItemBox extends Auto_buyItemBox { iconData = null onLoad(): void { super.onLoad(); } onEnable(): void { super.onEnable(); this.ui_bgMask.on(Node.EventType.TOUCH_END, this.click_bgMask, this); } onDisable(): void { super.onDisable(); this.ui_bgMask.off(Node.EventType.TOUCH_END, this.click_bgMask, this); } click_bgMask() { this.close(2); } onInit(): void { this.showOpenMaskEff(2); this.showOpenCenterEff(); //获取配置 //[target.itemIndex,target.suipianId,target.goodId,target.zhekouNum,target.buyType,target.buyPrice,target.buyNum] this.iconData = this.prema; let suiPianShopList = gg.data.table.getTableList(TableNames.Shop); let shopItemData = suiPianShopList.find((item)=>item.id == this.iconData[1]); this.lb_name.string = gg.lang.get(shopItemData.name); let itemData = gg.data.table.getItemData(shopItemData.frag); // let desc = shopItemData.name.replace('碎片', '') this.lb_desc.string = gg.lang.get(itemData.desc1); this.lb_num.string = 'x' + this.iconData[6]; let type = this.iconData[4]; let price = this.iconData[5]; let zhekouNum = this.iconData[3]; if (zhekouNum == 10) { this.sp_zhekou.node.active = false; this.lb_zhekou.node.active = false; } else { this.sp_zhekou.node.active = true; this.lb_zhekou.node.active = true; this.lb_zhekou.string = zhekouNum + gg.lang.get('折')//zhekouNum + '折' } if(type == 1){ this.ui_layout.getChildByName('金币').active = true this.ui_layout.getChildByName('钻石').active = false this.lb_buy.string = price.toString() }else{ this.ui_layout.getChildByName('金币').active = false this.ui_layout.getChildByName('钻石').active = true this.lb_buy.string = price.toString() } // let mainView = this.node.getChildByName('mainView') // mainView.scale = v3(0.1,0.1,0.1) // tween(mainView) // .to(0.5,{scale:v3(1,1,1)},{easing:'elasticOut'}) // .start() } protected start(): void { this.ui_center.getComponent(itemPic).setGoodId(this.iconData[2]) } click_btnClose(): void { gg.audio.playEffect({ name: "点击音效"}); this.close(2) } click_btnBuy(){ gg.audio.playEffect({ name: "点击音效"}); let index = this.iconData[0] let type = this.iconData[4] let price = this.iconData[5] let localStr = gg.data.getStringData(OtherDataType.ShopBuyListData) let shopItemList = [] shopItemList = localStr.split('&') let shopItemData = shopItemList[index] gg.targetTaskManager.statisticalData(TargetTaskType.buyFragment, 1); let num = this.iconData[6] let goodId = this.iconData[2] if(type == 1){ let myGolde = gg.data.getItemNum(ItemNumType.money); if(myGolde < price){ gg.ui.showToast('余额不足') return } gg.data.addDayTaskProgressData(TaskType.shopBuyWeaponS,1) gg.data.subItemNum(ItemNumType.money,price) //gg.data.addItemNum(goodId,num) let array = shopItemData.split('|') array[2] = '1' shopItemList[index] = array.join('|') gg.data.setStringData(OtherDataType.ShopBuyListData,shopItemList.join('&')) //发出消息 GEvent.Ins.emit(GEvent.checkShopItem, index) let itemsArray = [] let id = goodId//钱 let item = new ItemData(id,num) item.num = num item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); this.close(2) }else{ let myDiamond = gg.data.getDiamond(); if(myDiamond < price){ gg.ui.showToast('钻石不足') return } gg.data.addDayTaskProgressData(TaskType.shopBuyWeaponS,1) gg.data.subDiamond(price) //gg.data.addItemNum(goodId,num) let array = shopItemData.split('|') array[2] = '1' shopItemList[index] = array.join('|') gg.data.setStringData(OtherDataType.ShopBuyListData,shopItemList.join('&')) GEvent.Ins.emit(GEvent.checkShopItem, index) //弹出弹窗 let itemsArray = [] let id = goodId//钱 let item = new ItemData(id,num) item.num = num item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); this.close(2) } gg.sdk.reportDY("inLevel", `商店-购买物品`) } }