消消方块阵换皮表情
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.

121 lines
4.5 KiB

1 week ago
import { _decorator, Component, instantiate, Label, Node, RichText, Sprite, tween, v3 } from 'cc';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { GBundle, GPath, UIID } from '../../game/ConfigRes';
import { TableNames } from '../../game/ConfigTableData';
import { ItemData } from '../../game/ConfigProjectData';
import { ItemGrid } from '../../com/ItemGrid';
import { NewFunType } from '../../newFun/NewFun';
import { OtherDataType, StatisticsType } from '../../game/GameData';
import { ChapterDifficulty } from '../../manager/ChapterDataManager';
const { ccclass, property } = _decorator;
@ccclass('ReplicaItem')
export class ReplicaItem extends Component {
bg: Sprite = null;
lbtitle: Label = null;
rewardNode: Node = null;
lockNode: Node = null;
countNode: Node = null;
rtDesc: RichText = null;
lbCount: Label = null;
lockMask: Node = null;
protected onLoad(): void {
this.lockMask = this.node.find("lockMaskNode");
this.bg = this.node.find("bg").getComponent(Sprite);
this.lbtitle = this.node.find("lbtitle").getComponent(Label);
this.rewardNode = this.node.find("rewardNode");
this.lockNode = this.node.find("lockNode");
this.countNode = this.node.find("countNode");
this.rtDesc = this.lockNode.find("rtDesc").getComponent(RichText);
this.lbCount = this.countNode.find("lbCount").getComponent(Label);
}
protected onEnable(): void {
this.node.on(Node.EventType.TOUCH_END, this.onClick, this);
}
protected onDisable(): void {
this.node.off(Node.EventType.TOUCH_END, this.onClick, this);
}
Data: ITableReplica = null;
chapter: ITableChapter = null;
itemRewards: ItemData[] = null;
newFunData: ITableNewFun = null;
unlockChapter: number = 0;
haveCount: number = 0;
maxCount: number = 0;
curentCount: number = 0;
setData(data: ITableReplica) {
this.Data = data;
this.chapter = gg.data.table.getTableData<ITableChapter>(TableNames.Chapter, this.Data.chapterID[0]);
if (!this.chapter){
return;
}
let rewardStr = gg.data.project.getChapterRewardStr(this.chapter.id, ChapterDifficulty.Normal);
this.itemRewards = gg.game.parseRewardStr(rewardStr);
this.newFunData = gg.newFun.getNewFunData(NewFunType.Replica, this.Data.id);
this.unlockChapter = this.newFunData.chapter;
this.node.scale = v3(0.4, 0.4, 0.4);
let str = gg.data.getkeyKeyValue(OtherDataType.ReplicaCanEnterCountToday, this.Data.id);
this.maxCount = this.Data.count;
this.curentCount = Number(str) || 0;
this.haveCount = Math.max(0, this.maxCount - this.curentCount);
tween(this.node)
.to(0.3, { scale: v3(1, 1, 1) }, { easing: 'elasticOut' })
.start();
this.updateUI();
}
updateUI() {
this.bg.node.getOrAddComponent(SpriteLoad).setSprite(GPath.texture("title_" + this.Data.id), GBundle.Replica);
this.lbtitle.string = this.Data.name;
this.rewardNode.children.map(x => x.active = false);
for (let i = 0; i < this.itemRewards.length; i++) {
let item = this.itemRewards[i];
let n: Node = null;
if (i < this.rewardNode.children.length) {
n = this.rewardNode.children[i];
} else {
n = gg.res.getNode("prefab/", "ItemGrid", GBundle.Comm2);
if (!n) {
console.warn("ReplicaItem: ItemGrid prefab not ready", GBundle.Comm2);
continue;
}
n.parent = this.rewardNode;
n.active = true;
}
n.active = true;
n.scale = v3(0.8, 0.8, 0.8);
// if (i == 0) {
// n.scale = v3(0.8, 0.8, 0.8);
// } else {
// n.scale = v3(0.5, 0.5, 0.5);
// }
n.getComponent(ItemGrid).setData(item);
}
this.lockNode.active = !gg.newFun.isUnLockReplica(this.Data.id);
this.lockMask.active = !gg.newFun.isUnLockReplica(this.Data.id);
this.rtDesc.string = gg.lang.get(`通过第{1}章解锁`, [this.unlockChapter]);
this.countNode.active = !this.lockNode.active;
this.lbCount.string = `(${this.haveCount}/${this.maxCount})`;
}
onClick() {
if (this.lockNode.active) {
gg.ui.showToast(gg.lang.get('通关第{1}章节解锁', [this.unlockChapter]), false);
return;
}
gg.ui.openPanel(UIID.ReplicaBox, { data: this.Data });
}
}