You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/script/ui/GetReward/RewardGrid.ts

125 lines
4.6 KiB

3 weeks ago
import { _decorator, Component, Label, Node, Sprite } from 'cc';
import { ItemData } from '../../game/ConfigProjectData';
import MTools from 'db://assets/mx/tools/MTools';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { GBundle, GPath, UIID } from '../../game/ConfigRes';
import { applyItemQualityFrame } from '../../com/ItemQualityFrame';
const { ccclass, property } = _decorator;
@ccclass('RewardGrid')
export class RewardGrid extends Component {
pinjiBg: Sprite;
icon: Sprite
num: Label
suipianNode: Node;
qDowneff: Node = null;
qUpeff: Node = null;
onLoad() {
this.pinjiBg = this.node.getChildByName('品级框')?.getComponent(Sprite);
this.icon = this.node.getChildByName('icon')?.getComponent(Sprite);
this.num = this.node.getChildByName('numLab')?.getComponent(Label);
this.suipianNode = this.node.getChildByName('碎片');
this.qDowneff = this.node.find("qDowneff");
this.qUpeff = this.node.find("qUpeff");
//获取
}
Data: ItemData = null;
setData(data) {
this.Data = data;
this.updateUI();
}
updateUI() {
if (this.Data.isEquip) {
const eq = gg.equip.getEquip(this.Data.id);
if (!eq) {
console.log('[RewardGrid] 成品武器配表缺失', this.Data.id);
return;
}
if (this.suipianNode) this.suipianNode.active = false;
const name = String(eq.name ?? '').trim();
this.num.string = 'x' + MTools.formatChineseUnit({ num: this.Data.num });
if (name) {
this.icon.getComponent(SpriteLoad).setSprite(`weapon/${name}`, GBundle.Items);
}
this.applyIconScale(0);
this.pinjiBg.getComponent(SpriteLoad).setSprite(GPath.PingjiKuang('品质' + eq.quality), GBundle.Items);
return;
}
if (this.Data.isFragment) {
//武器id需要通过转换为碎片id获取配置信息
this.suipianNode.active = false
let conf = gg.data.project.getWeaponData(this.Data.id);
let suipianId = gg.data.project.getWeaponScrapId(conf.id);
let itemData = gg.data.table.getItemData(suipianId)
if (suipianId == 0) {
// console.log('武器id不存在碎片id', this.Data.id)
return
}
this.icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items);
this.applyIconScale(itemData.type);
//是否有武器
let isHaveWeapon = gg.data.project.isWeaponUnlocked(this.Data.id);
if (isHaveWeapon) {
1 week ago
// 有武器转为碎片:按 Weapon.synthesisnumber(Item 无 transition)
this.suipianNode.active = true;
const scrapMul = Math.max(1, gg.data.project.getWeaponFlagNumByLevel(this.Data.id));
this.num.string = 'x' + MTools.formatChineseUnit({ num: this.Data.num * scrapMul });
3 weeks ago
} else {
//没有武器正常数量
this.suipianNode.active = false
this.num.string = 'x' + MTools.formatChineseUnit({ num: this.Data.num });
}
this.setPingjiKuang(itemData);
} else {
let itemData = gg.data.table.getItemData(this.Data.id)
//item物品
this.num.string = 'x' + MTools.formatChineseUnit({ num: this.Data.num });
this.icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items);
this.applyIconScale(itemData.type);
//更加id获取type 碎片id换武器
if (this.suipianNode) {
this.suipianNode.active = itemData.type == 10;
}
this.setPingjiKuang(itemData);
}
}
private setPingjiKuang(itemData: ITableItem) {
applyItemQualityFrame(this.pinjiBg.getComponent(SpriteLoad), itemData);
this.qDowneff.children.map(x => x.active = x.name == itemData.quality + "");
this.qUpeff.children.map(x => x.active = x.name == itemData.quality + "");
}
/** 道具 icon 缩放:type10=0.6,其它=0.35 */
private applyIconScale(itemType: number) {
const iconScale = itemType == 10 ? 0.6 : 0.35;
this.icon.node.setScale(iconScale, iconScale, 1);
}
openDetailBtnClick() {
if (!this.Data) {
return
}
if (this.Data.id == 1) {
return
}
//打开界面 UIID.ItemDetailBox
gg.ui.openPanel(UIID.ItemDetailBox, {
data: this.Data
})
}
}