//*********************
// create by 流云
// time: Wed Sep 17 2025
// desc:
//*********************
import { _decorator, instantiate, v3, tween, Label, RichText, Sprite, sp } from 'cc';
import { Auto_TurnTable } from './Auto_TurnTable';
import { LotteryItem, TurnTableAwardType, TurnTableDataManager } from '../../manager/TurnTableDataManager';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { GPath, GBundle } from '../../game/ConfigRes';
import { SkillDataManager, SkillQuality } from '../../manager/SkillDataManager';
import { BattleDataManager } from '../BattleGame/BattleDataManager';
import BeginnerGuideManager, { BeginnerGuideType } from '../BattleGame/BeginnerGuideManager';
import { BattleType, ChapterDifficulty } from '../../manager/ChapterDataManager';
import { TableNames } from '../../game/ConfigTableData';
const { ccclass, property } = _decorator;
@ccclass('UITurnTable')
export class UITurnTable extends Auto_TurnTable {
/**圈数1 */
circleNum1: number = 6
/**圈数2 */
circleNum2: number = 4
/**旋转时间 */
rotateTime: number = 5
/**是否用过再抽一次 */
isUseRotateAgain: boolean = false
/**当前轮数 */
curRoundNum: number = 1
/**转盘奖励池 */
awardPoolList: LotteryItem[] = []
/**当前指向的长指针索引 */
currentLongIndex: number = -1;
/**当前指向的短指针索引 */
currentShortIndex: number = -1;
/**当前轮结果id数组 */
currentRoundResultIdArr: number[] = [];
/**所有轮结果id数组 */
allRoundResultIdArr: number[] = [];
resultItemList: LotteryItem[] = []
onLoad(): void {
super.onLoad();
}
onEnable(): void {
super.onEnable();
gg.game.CurentBattle.pause('TurnTable')
}
onDisable(): void {
super.onDisable();
gg.game.CurentBattle.onBlockingPanelClosed();
}
onInit(): void {
this.index = this.prema;
this.initTurnTable()
}
index = 0;
/**初始化转盘 */
initTurnTable() {
gg.PRR.addSkillData(10);
TurnTableDataManager.initAvailableTurnTableIdArr()
this.awardPoolList = TurnTableDataManager.getAllTurnTableAwardList(this.index)
for (let i = 0; i < this.awardPoolList.length; i++) {
let item = instantiate(this.ui_singleItem)
item.active = true
item.position = v3(0, 0, 0)
item.parent = this.ui_tableContent.children[i]
this.initItem(item, this.awardPoolList[i])
}
//console.log('this.awardPoolList', this.awardPoolList);
this.hideAllBtn()
this.scheduleOnce(() => {
this.startRotate()
}, 1)
}
/**初始化单个物品 */
initItem(item, awardItem: LotteryItem) {
if (awardItem.awardType == TurnTableAwardType.Coin) {
item.getChildByName('itemSpr').getComponent(SpriteLoad).setSprite(GPath.TurnTableRogue(`色阶${awardItem.awardQuality}`), GBundle.TurnTable);
item.getChildByName('chengse').active = awardItem.awardQuality == SkillQuality.Orange
item.getChildByName('zise').active = awardItem.awardQuality == SkillQuality.Purple
item.getChildByName('iconSpr').getComponent(SpriteLoad).setSprite(GPath.TurnTableRogue(`银币`), GBundle.TurnTable);
item.getChildByName('lb_num').getComponent(Label).string = awardItem.awardNum.toString()
item.getChildByName('数值框').active = true
item.getComponentsInChildren(Sprite).forEach(x => x.grayscale = false);
} else if (awardItem.awardType == TurnTableAwardType.Skill || awardItem.awardType == TurnTableAwardType.SpecialSkill || awardItem.awardType == TurnTableAwardType.PurpleSkill) {
let skillConfig: ITableSkill = SkillDataManager.getSkillDataById(awardItem.awardSkillConfig.id)
item.getChildByName('itemSpr').getComponent(SpriteLoad).setSprite(GPath.TurnTableRogue(`色阶${skillConfig.quality}`), GBundle.TurnTable);
item.getChildByName('chengse').active = skillConfig.quality == SkillQuality.Orange
item.getChildByName('zise').active = skillConfig.quality == SkillQuality.Purple
item.getChildByName('iconSpr').getComponent(SpriteLoad).setSprite(GPath.SkillItem(skillConfig.icon), GBundle.Items);
item.getChildByName('lb_num').getComponent(Label).string = gg.lang.get(skillConfig.name)
item.getChildByName('数值框').active = false
item.getComponentsInChildren(Sprite).forEach(x => x.grayscale = false);
}
}
/**开始转动 */
startRotate() {
// let isFirst = this.curRoundNum == 1
this.resetAllTriangles()
if (this.curRoundNum <= 2) {
TurnTableDataManager.removeUnavailableTurnTableId(this.currentRoundResultIdArr)
}
this.currentRoundResultIdArr = TurnTableDataManager.getTwoRandomAwardByWeight(this.curRoundNum)
this.currentLongIndex = this.currentRoundResultIdArr[0] - 1
this.currentShortIndex = this.currentRoundResultIdArr[1] - 1
// 计算目标角度
const targetAngle1 = -(this.circleNum1 * 360 + this.currentLongIndex * 36 + 36 / 2); // 圈数1 + 目标角度
const targetAngle2 = -(this.circleNum2 * 360 + this.currentShortIndex * 36 + 36 / 2); // 圈数2 + 目标角度
this.ui_pointer1.angle = 0
this.ui_pointer2.angle = 0
// 使用tween实现旋转动画
tween(this.ui_pointer1)
.by(this.rotateTime, { angle: targetAngle1 }, {
easing: "cubicOut",
onUpdate: () => {
this.updatePointerHighlight(0); // 更新长指针高亮
},
onComplete: () => {
this.rotateEnd();
}
})
.start();
tween(this.ui_pointer2)
.by(this.rotateTime, { angle: targetAngle2 }, {
easing: "cubicOut",
onUpdate: () => {
this.updatePointerHighlight(1); // 更新短指针高亮
},
})
.start();
}
// 重置所有三角形高亮
private resetAllTriangles() {
for (let i = 0; i < this.ui_highLightParent.children.length; i++) {
this.setTriangleHighlight(i, false);
}
}
// 设置三角形高亮状态
private setTriangleHighlight(index: number, highlight: boolean) {
const triangleNode = this.ui_highLightParent.children[index];
if (highlight) {
triangleNode.active = true // 高亮颜色
} else {
triangleNode.active = false // 恢复正常颜色
}
}
// 更新指针指向的高亮区域
private updatePointerHighlight(pointerType: number) {
const pointer = pointerType === 0 ? this.ui_pointer1 : this.ui_pointer2;
const angle = pointer.angle % 360;
const triangleIndex = this.getTriangleIndexByAngle(angle);
if (pointerType === 0) {
if (this.currentLongIndex !== -1) {
this.setTriangleHighlight(this.currentLongIndex, false);
}
if (triangleIndex != this.currentLongIndex) {
gg.audio.playEffect({ name: "转盘" });
}
this.currentLongIndex = triangleIndex;
this.setTriangleHighlight(this.currentLongIndex, true);
} else {
if (this.currentShortIndex !== -1) {
this.setTriangleHighlight(this.currentShortIndex, false);
}
this.currentShortIndex = triangleIndex;
this.setTriangleHighlight(this.currentShortIndex, true);
}
}
// 根据角度获取三角形索引
private getTriangleIndexByAngle(angle: number): number {
// 将角度转换为0-360范围
let normalizedAngle = (angle + 36) % 360;
if (normalizedAngle < 0) normalizedAngle += 360;
// 每个三角形占36度
const triangleAngle = 36;
let index = Math.floor(normalizedAngle / triangleAngle);
// 调整索引,使0索引对应正上方
index = (10 - index) % 10;
return index;
}
/**转盘结束 */
rotateEnd() {
this.highlightCurrentRoundResult()
}
/**隐藏按钮 */
hideAllBtn() {
this.btnAgain.active = false
this.btnGetAward.active = false
this.btnRestart.active = false
}
/**显示按钮 */
showAllBtn() {
this.btnAgain.active = this.curRoundNum < 2
this.btnAgain.getChildByName('视频标').active = gg.game.CurentSelectChapterId != 1
this.btnGetAward.active = true
this.btnRestart.active = this.curRoundNum >= 2
}
/**转盘上结果高亮闪烁 */
highlightCurrentRoundResult() {
gg.audio.playEffect({ name: "转盘选中音效" });
tween(this.ui_highLightParent)
.to(0.25, { opacity: 0 })
.to(0.25, { opacity: 255 })
.to(0.25, { opacity: 0 })
.to(0.25, { opacity: 255 })
.call(() => {
this.showCurrentRoundBottomResult()
})
.start()
}
/**显示当前轮结果 */
showCurrentRoundBottomResult() {
this.allRoundResultIdArr.push(...this.currentRoundResultIdArr)
this.ui_againTipBox.active = this.curRoundNum == 1
//展示底部当前轮结果
for (let i = 0; i < this.currentRoundResultIdArr.length; i++) {
let config = this.awardPoolList.find(x => x.id == this.currentRoundResultIdArr[i])
let item = instantiate(this.ui_singleItem)
item.active = true
item.position = v3(0, 0, 0)
item.scale = v3(0, 0, 0)
let n = (this.curRoundNum - 1) * 2 + i
if (this.curRoundNum >= 3) {
n = 2 + i
}
item.parent = this.ui_awardBottom.getChildByName(`item_${n}`)
this.initItem(item, config)
tween(item)
.to(0.3, { scale: v3(1.2, 1.2, 1) })
.to(0.15, { scale: v3(0.9, 0.9, 1) })
.to(0.15, { scale: v3(1, 1, 1) })
.start()
}
//转盘上结果置灰
for (let i = 0; i < this.ui_tableContent.children.length; i++) {
let itemParent = this.ui_tableContent.children[i]
itemParent.getComponentsInChildren(Sprite).forEach(x => { if (this.currentRoundResultIdArr.includes(this.awardPoolList[i].id)) { x.grayscale = true } });
if (this.currentRoundResultIdArr.includes(this.awardPoolList[i].id)) {
itemParent.children[0].getChildByName('chengse').active = false
itemParent.children[0].getChildByName('zise').active = false
}
// itemParent.getComponentsInChildren(sp.Skeleton).forEach(x => x.node.active = !this.allRoundResultIdArr.includes(this.awardPoolList[i].id));
}
this.scheduleOnce(() => {
this.shouFinalResult()
this.showAllBtn()
this.showNewGuide()
}, 1)
}
/**
* 清空第二次随机出的物品
*/
clearSecondRandomItem() {
this.ui_awardBottom.getChildByName(`item_2`).destroyAllChildren()
this.ui_awardBottom.getChildByName(`item_3`).destroyAllChildren()
//将上一次置灰的物品恢复正常
for (let i = 0; i < this.ui_tableContent.children.length; i++) {
let itemParent = this.ui_tableContent.children[i]
itemParent.getComponentsInChildren(Sprite).forEach(x => { if (this.currentRoundResultIdArr.includes(this.awardPoolList[i].id)) { x.grayscale = false } });
}
}
/**展示最终结果 */
shouFinalResult() {
this.ui_result.active = true
// this.ui_awardContent.destroyAllChildren()
if (this.curRoundNum >= 3) {
this.ui_awardContent.children[3].removeFromParent()
this.ui_awardContent.children[2].removeFromParent()
}
for (let i = 0; i < this.currentRoundResultIdArr.length; i++) {
let item = instantiate(this.ui_awardItem)
item.active = true
item.parent = this.ui_awardContent
let awardItem: LotteryItem = this.awardPoolList.find(x => x.id == this.currentRoundResultIdArr[i])
this.initResultItem(item, awardItem)
this.resultItemList.push(awardItem)
}
}
/**初始化单个物品 */
initResultItem(item, awardItem: LotteryItem) {
item.getChildByName('呼吸光').active = this.curRoundNum == 2
if (awardItem.awardType == TurnTableAwardType.Coin) {
item.getChildByName('qSpr').getComponent(SpriteLoad).setSprite(GPath.Comm2Texture(`品质${awardItem.awardQuality}`), GBundle.Comm2);
item.getChildByName('iconSpr').getComponent(SpriteLoad).setSprite(GPath.TurnTableRogue(`银币`), GBundle.TurnTable);
item.getChildByName('lb_name').getComponent(Label).string = gg.lang.get(`银币`)//`银币`
item.getChildByName('desc_richText').getComponent(RichText).string = gg.lang.get(`奖励银币{1}`, [awardItem.awardNum])//`奖励银币+${awardItem.awardNum}`
} else if (awardItem.awardType == TurnTableAwardType.Skill || awardItem.awardType == TurnTableAwardType.SpecialSkill || awardItem.awardType == TurnTableAwardType.PurpleSkill) {
let skillConfig: ITableSkill = SkillDataManager.getSkillDataById(awardItem.awardSkillConfig.id)
item.getChildByName('qSpr').getComponent(SpriteLoad).setSprite(GPath.Comm2Texture(`品质${skillConfig.quality}`), GBundle.Comm2);
item.getChildByName('iconSpr').getComponent(SpriteLoad).setSprite(GPath.SkillItem(skillConfig.icon), GBundle.Items);
item.getChildByName('lb_name').getComponent(Label).string = gg.lang.get(skillConfig.name)//skillConfig.name
item.getChildByName('desc_richText').getComponent(RichText).string = gg.lang.get(skillConfig.desc)//skillConfig.desc
}
}
click_btnAgain() {
gg.audio.playEffect({ name: "点击音效" });
let curWaveNum = gg.game.CurentBattle.CurentWaveNum
let func = () => {
this.ui_result.active = false
this.hideAllBtn()
this.ui_againTipBox.active = false
this.curRoundNum++
this.startRotate()
}
if (gg.game.CurentSelectChapterId == 1) {
gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-转盘再抽一次`)
func()
} else {
gg.sdk.showVideoAd((res) => {
if (res) {
gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-AD-转盘再抽一次`)
func()
gg.game.CurentBattle.IsWatchAd = true
gg.PRR.AdClickNum.push(3)
} else {
gg.ui.showToast('观看视频失败');
}
})
}
}
click_btnRestart() {
gg.audio.playEffect({ name: "点击音效" });
let curWaveNum = gg.game.CurentBattle.CurentWaveNum
let func = () => {
//删除数组后两个
this.resultItemList.splice(this.resultItemList.length - 2, 2)
this.clearSecondRandomItem()
this.ui_result.active = false
this.hideAllBtn()
this.ui_againTipBox.active = false
this.curRoundNum++
// if(this.curRoundNum > 3){
// this.curRoundNum = 3
// }
this.startRotate()
}
gg.sdk.showVideoAd((res) => {
if (res) {
gg.sdk.reportDY("inLevel", `章节${gg.game.CurentBattle.getReportDYChapterId()}_${curWaveNum}-AD-转盘重抽一次`)
func()
gg.game.CurentBattle.IsWatchAd = true
gg.PRR.AdClickNum.push(4)
} else {
gg.ui.showToast('观看视频失败');
}
})
}
click_btnGetAward() {
gg.audio.playEffect({ name: "点击音效" });
let coinNum = 0;
let skills: ITableSkill[] = []
let indexArr = [];
for (let i = 0; i < this.resultItemList.length; i++) {
let awardItem = this.resultItemList[i]
if (awardItem.awardType == TurnTableAwardType.Coin) {
coinNum += awardItem.awardNum;
//BattleDataManager.addCurCoinNum(awardItem.awardNum)
gg.PRR.addSkillRefreshData(10, [awardItem.awardNum], false);
} else if (awardItem.awardType == TurnTableAwardType.Skill || awardItem.awardType == TurnTableAwardType.SpecialSkill || awardItem.awardType == TurnTableAwardType.PurpleSkill) {
let skill = gg.data.table.getTableData(TableNames.Skill, awardItem.awardSkillConfig.id)
skills.push(skill);
//gg.game.CurentBattle.addCurHaveSkillArr([awardItem.awardSkillConfig.id])
gg.PRR.addSkillRefreshData(10, [awardItem.awardSkillConfig.id], false);
}
indexArr.push(i);
}
gg.game.CurentBattle.addCoinNum(coinNum);
gg.game.CurentBattle.addCurHaveSkillArr(skills);
gg.PRR.finishAddSkillData(indexArr, this.curRoundNum);
this.close(2)
}
showNewGuide() {
if (
gg.game.CurentSelectChapterId == 1
&& this.curRoundNum == 1
&& gg.game.CurentBattle.BattleType == BattleType.Level
&& gg.game.CurentBattle.Difficulty == ChapterDifficulty.Normal
&& !gg.game.CurentBattle.IsTurnTableAgainGuideShown
) {//&& gg.data.getLocalGuideValue('引导多抽一次') == '0'
// gg.data.setLocalGuideValue('引导多抽一次', '1')
gg.game.CurentBattle.IsTurnTableAgainGuideShown = true
this.ui_guideMask.active = true
let firstNode = this.btnAgain
let finishCallBack = () => {
this.ui_guideMask.active = false
}
this.ui_guideMask.getComponent(BeginnerGuideManager).setIsGuideClick(BeginnerGuideType.DIANJI)
this.ui_guideMask.getComponent(BeginnerGuideManager).setBindNode(firstNode, finishCallBack,
gg.lang.get('转盘再抽一次'), 1, 1200)
}
}
}