import { _decorator, Component, Label, Node } from 'cc'; import { IRoleLevelUpData, ConfigTableData, TableNames } from '../../game/ConfigTableData'; import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; import { GPath, GBundle, UIID } from '../../game/ConfigRes'; import { ItemData } from '../../game/ConfigProjectData'; import MTools from 'db://assets/mx/tools/MTools'; const { ccclass, property } = _decorator; // 1、道具类 // 2、武器 // 3、特殊效果类 // 4、进阶 enum LevelupType { Prop = 1, Weapon = 2, Special = 3, Advance = 4, } @ccclass('LevelupIcon') export class LevelupIcon extends Component { _level = 0 curType = LevelupType.Prop itemId = 0 itemNum = 0 curConfig: IRoleLevelUpData = null start() { } setLevel(level: number, isHeng = true) { this._level = level let configList = gg.data.table.getTableList(TableNames.Character); if (!configList) { this.node.active = false; } else { //当前等级的配置 let config = configList.find((item) => item.level == this._level); if (config) { this.curConfig = config this.node.active = true; if (config.type == 0) { //当前类型的配置 this.node.active = false } else { //有奖励 this.curType = config.type; if (this.curType == LevelupType.Advance) { this.node.getChildByName("阶级标").active = true; let lable = this.node.getChildByName("阶级标").getChildByName('Label').getComponent(Label); lable.string = gg.lang.get(config.rank); this.node.getChildByName("icon").active = false; this.node.getChildByName('Label').active = false; //dikuang this.node.getChildByName("dikuang").active = false; } else { this.node.getChildByName("icon").active = true; this.node.getChildByName('Label').active = true; //dikuang this.node.getChildByName("dikuang").active = true this.node.getChildByName("阶级标").active = false; let numLab = this.node.getChildByName('Label').getComponent(Label); numLab.string = 'x' + config.num + ""; let icon = this.node.getChildByName("icon"); let name = icon.getChildByName('name')?.getComponent(Label) if (name && name.node) { name.node.active = false } icon.active = true; let itemConfig = null if (this.curType == LevelupType.Prop || this.curType == LevelupType.Special) { itemConfig = gg.data.table.getItemData(config.prop_id) icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemConfig.icon), GBundle.Items); if (config.prop_id == 98 || config.prop_id == 99 || config.prop_id == 97) { if (name && name.node) { name.node.active = true name.string = gg.lang.get(itemConfig.name) } } } else if (this.curType == LevelupType.Weapon) { // let weaponId = config.prop_id; //武器icon转碎片icon let conf = gg.data.project.getWeaponData(weaponId); let suipianId = conf.scrapId itemConfig = gg.data.table.getItemData(suipianId) icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemConfig.icon), GBundle.Items); } let quality = itemConfig.quality || 1 if (isHeng) { this.node.getChildByName("dikuang").getComponent(SpriteLoad).setSprite(GPath.LevelUpIconH("H" + quality), GBundle.Items); } else { this.node.getChildByName("dikuang").getComponent(SpriteLoad).setSprite(GPath.LevelUpIconV("V" + quality), GBundle.Items); } this.itemId = config.prop_id; this.itemNum = config.num; } } } else { this.node.active = false; } } } itemClick() { gg.audio.playEffect({ name: "点击音效" }); if (this.curType == LevelupType.Prop || this.curType == LevelupType.Special) { let item = new ItemData(this.itemId, this.itemNum) gg.ui.openPanel(UIID.ItemDetailBox2, { data: item }) } else if (this.curType == LevelupType.Weapon) { let item = new ItemData(this.itemId, this.itemNum) item.isFragment = true gg.ui.openPanel(UIID.ItemDetailBox2, { data: item }) } } //获取奖励 getLevelUpReward(level) { if (this._level != level) { return } if (!this.curConfig || !this.node.active) { return; } else { //领取奖励 if (this.curType == LevelupType.Prop) { //碎片 if (this.itemId >= 104 && this.itemId <= 107) { let boxRewardArray = gg.data.getFragmentNumArray(this.itemId + ',' + this.itemNum) let statsArray = MTools.mergeToStatsArray(boxRewardArray) let itemsArray = [] for (let i = 0; i < statsArray.length; i++) { let array = statsArray[i].split('|') let item = new ItemData(Number(array[0]), Number(array[1])) itemsArray.push(item) } gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); } else { let itemsArray = [] let id = this.itemId let item = new ItemData(id, this.itemNum) item.num = this.itemNum item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); } } else if (this.curType == LevelupType.Special) { let itemsArray = [] let id = this.itemId let item = new ItemData(id, this.itemNum) item.num = this.itemNum item.id = id itemsArray.push(item) gg.ui.openPanel(UIID.GetReward, { data: itemsArray, onClose: () => { } }); } else if (this.curType == LevelupType.Weapon) { //武器奖励 let isHaveWeapon = gg.data.project.isWeaponUnlocked(this.itemId); if (isHaveWeapon) { //有武器转为碎片数量 //武器属性 let weaponData = gg.data.project.getWeaponData(this.itemId); let itemData = gg.data.table.getItemData(weaponData.scrapId) gg.data.addItemNum(weaponData.scrapId, itemData.transition); } else { //没有武器添加武器数据 gg.data.project.unlockWeapon(this.itemId); } gg.data.saveLocal(); gg.data.saveToServer(); gg.ui.popPanel(UIID.GetNewGoodid, { data: this.itemId }); } else if (this.curType == LevelupType.Advance) { //障碍物奖励 } } } }