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

200 lines
7.4 KiB

1 week ago
//*********************
// create by 流云
// time: Thu Mar 26 2026
// desc:
//*********************
import { _decorator, Component, Node, find, v3, Label, Color } from 'cc';
import { Auto_ReplicaBox } from './Auto_ReplicaBox';
import { ColorDefance, ItemData } from '../../game/ConfigProjectData';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { GBundle, GPath, UIID } from '../../game/ConfigRes';
import { BattleType, ChapterDifficulty } from '../../manager/ChapterDataManager';
import { OtherDataType } from '../../game/GameData';
import { TableNames } from '../../game/ConfigTableData';
import { ItemGrid } from '../../com/ItemGrid';
const { ccclass, property } = _decorator;
@ccclass('UIReplicaBox')
export class UIReplicaBox extends Auto_ReplicaBox {
onLoad(): void {
super.onLoad();
}
onEnable(): void {
super.onEnable();
}
onDisable(): void {
super.onDisable();
}
onInit(): void {
this.showOpenCenterEff();
this.showOpenMaskEff(2);
this.Data = this.prema;
let numStr = gg.data.getkeyKeyValue(OtherDataType.LastDifficultySelect, this.Data.id, true);
this.difficulty = parseInt(numStr) || ChapterDifficulty.Easy;
if (this.difficulty < this.Data.opendifficulty[0])
this.difficulty = this.Data.opendifficulty[0];
if (this.difficulty > this.Data.opendifficulty[1])
this.difficulty = this.Data.opendifficulty[1];
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);
let sweepStr = gg.data.getkeyKeyValue(OtherDataType.SweepNum, this.Data.id);
this.dailySweepCount = Number(sweepStr) || 0;
this.dailySweepCountMax = this.Data.sweepFree + this.Data.sweepAd;
this.updateUI();
}
chapter: ITableChapter = null;
Data: ITableReplica = null;
itemRewards: ItemData[] = null;
haveCount: number = 0;
curentCount: number = 0;
maxCount: number = 0;
difficulty: ChapterDifficulty = ChapterDifficulty.Easy;
/**每日扫荡次数 */
dailySweepCount: number = 0;
/**每日扫荡次数上限 */
dailySweepCountMax: number = 0;
/**今日是否已经通关 */
isCompleteToday: boolean = false;
updateUI() {
this.chapter = gg.data.table.getTableData<ITableChapter>(TableNames.Chapter, this.Data.chapterID[this.difficulty - 1]);
gg.data.project.vigourCost = this.chapter.chapter_enery;
let rewardStr = gg.data.project.getChapterRewardStr(this.chapter.id, this.difficulty);
this.itemRewards = gg.game.parseRewardStr(rewardStr);
this.lb_name.string = this.Data.name;
this.ui_titleBg.getOrAddComponent(SpriteLoad).setSprite(GPath.texture("bg_" + this.Data.id), GBundle.Replica);
this.ui_difficultybg.getOrAddComponent(SpriteLoad).setSprite(GPath.texture("difficultybg_" + this.difficulty), GBundle.Replica);
this.ui_finish.active = gg.data.project.isReplicaComplete(this.Data.id, this.difficulty);
//判断当前副本难度到了那一个难度
this.ui_difficut.children.forEach((item, index) => {
item.active = index == this.difficulty - 1;
})
this.ui_layNode.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.ui_layNode.children.length) {
n = this.ui_layNode.children[i];
} else {
n = gg.res.getNode("prefab/", "ItemGrid", GBundle.Comm2);
if (!n) {
console.warn("UIReplicaBox: ItemGrid prefab not ready", GBundle.Comm2);
continue;
}
n.parent = this.ui_layNode;
n.active = true;
}
n.active = true;
n.scale = v3(0.8, 0.8, 0.8);
n.getComponent(ItemGrid)?.setData(item);
}
this.lb_tiaozhan.string = `(${this.haveCount}/${this.maxCount})`;
let currentVigour = gg.data.getVigour();
let needVigour = gg.data.project.vigourCost;
this.lb_needTili.string = `x${needVigour}`;
this.lb_needTili.outlineColor = currentVigour >= needVigour ? Color.BLACK : Color.RED;
this.btnLeft.active = this.difficulty > this.Data.opendifficulty[0];
this.btnRight.active = this.difficulty < this.Data.opendifficulty[1];
this.btnTiaozhan.active = this.haveCount > 0 && (this.difficulty == ChapterDifficulty.Easy || gg.data.project.isReplicaComplete(this.Data.id, this.difficulty - 1));
this.ui_selectDiff.active = this.Data.opendifficulty[1] > this.Data.opendifficulty[0];
this.btnSweep.active = this.ui_finish.active && this.dailySweepCount < this.dailySweepCountMax;
this.btnSweep.getChildByName("video").active = this.dailySweepCount >= this.Data.sweepFree;
this.btnSweep.getChildByName("descLab").getComponent(Label).string = `剩余次数:${this.dailySweepCountMax - this.dailySweepCount}`;
if(this.ui_selectDiff.active){
//有难度选择显示才有没有结算的ui显示
//当前
if(!this.btnTiaozhan.active){
this.ui_unlock.active = true;
}else{
this.ui_unlock.active = false;
}
}else{
this.ui_unlock.active = false;
}
}
click_bgMask(): void {
this.close(2);
}
click_btnClose(): void {
this.close(2);
}
click_btnLeft(): void {
this.difficulty--;
if (this.difficulty < this.Data.opendifficulty[0]) {
this.difficulty = this.Data.opendifficulty[0];
}
this.updateUI();
}
click_btnRight(): void {
this.difficulty++;
if (this.difficulty > this.Data.opendifficulty[1]) {
this.difficulty = this.Data.opendifficulty[1];
}
this.updateUI();
}
click_btnSweep(): void {
if (this.dailySweepCount < this.Data.sweepFree) {
this.sweep();
} else {
gg.sdk.showVideoAd((res) => {
if (res) {
this.sweep();
}
})
}
}
click_btnTiaozhan(): void {
gg.game.CurentSelectReplica = this.Data;
gg.game.CurentSelectBattleType = this.Data.id;
gg.game.CurentSelectBattleDifficulty = this.difficulty;
gg.game.CurentSelectChapterId = this.Data.chapterID[this.difficulty - 1];
let ret = gg.game.enterBattle();
if (ret === 1) {
let str = gg.data.getkeyKeyValue(OtherDataType.ReplicaCanEnterCountToday, this.Data.id);
let next = (Number(str) || 0) + 1;
gg.data.setkeyKeyValue(OtherDataType.ReplicaCanEnterCountToday, this.Data.id, next);
}
}
sweep() {
this.dailySweepCount++;
this.curentCount++;
gg.data.setkeyKeyValue(OtherDataType.SweepNum, this.Data.id, this.dailySweepCount);
this.haveCount--;
gg.data.setkeyKeyValue(OtherDataType.ReplicaCanEnterCountToday, this.Data.id, this.curentCount);
this.updateUI();
let rewardStr = gg.data.project.getChapterRewardStr(this.chapter.id, this.difficulty);
gg.game.showGetRewardByReardStr(rewardStr);
}
}