import { _decorator, Component, Enum, Node } from 'cc'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { Dot } from './RedDot'; import { OtherDataType, StatisticsType } from 'db://assets/script/game/GameData'; import { sdkConfig } from 'db://assets/script/sdk/sdkConfig'; import { NewFunType } from 'db://assets/script/newFun/NewFun'; import { UIID } from 'db://assets/script/game/ConfigRes'; import { ChapterDifficulty } from 'db://assets/script/manager/ChapterDataManager'; const { ccclass, property } = _decorator; /** 红点类型(预留) */ export enum DotType { 默认 = 1, } /** 红点ID */ export enum RedDotID { 无 = 0, //主界面红点 主界面_挂机 = 101, 主界面_任务 = 102, 主界面_签到 = 103, 主界面_关卡 = 104, 主界面_排名 = 105, 主界面_商店 = 106, 主界面_角色 = 107, 主界面_武器 = 108, 主界面_超值赠礼 = 109, 主界面_基金收益 = 110, 主界面_月卡充值 = 111, 主界面_首充礼包 = 113, 主界面_邀请有礼 = 114, 主界面_每日礼包 = 115, 主界面_左章节红点 = 116, 主界面_右章节红点 = 117, 主界面_离线收益 = 118, //挂机页面红点 挂机页_扫荡 = 201, 挂机页_领取 = 202, //商店红点 商店_免费钻石 = 301, 商店_稀有宝箱 = 302, 商店_免费金币 = 303, } /** * 静态红点配置(动态生成的批量红点节点不建议走此配置,比如活动列表里生成的大量子节点红点) */ export const DotConfig: Array = [//根据游戏修改此处配置 //主界面红点 { id: RedDotID.主界面_挂机, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_任务, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_签到, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_关卡, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_排名, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_商店, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_角色, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_武器, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_离线收益, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_超值赠礼, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_基金收益, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_月卡充值, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_首充礼包, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_邀请有礼, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_每日礼包, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_左章节红点, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.主界面_右章节红点, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, //挂机页面红点 // 注意:这两个红点用于挂机页内部,不应反向影响主界面按钮红点(避免出现“主界面判断为0但仍亮”的冲突) { id: RedDotID.挂机页_扫荡, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, { id: RedDotID.挂机页_领取, type: DotType.默认, parentId: RedDotID.无, parent: null, status: 0, children: [] }, //商店红点 { id: RedDotID.商店_免费钻石, type: DotType.默认, parentId: RedDotID.主界面_商店, parent: null, status: 0, children: [] }, { id: RedDotID.商店_稀有宝箱, type: DotType.默认, parentId: RedDotID.主界面_商店, parent: null, status: 0, children: [] }, { id: RedDotID.商店_免费金币, type: DotType.默认, parentId: RedDotID.主界面_商店, parent: null, status: 0, children: [] }, ] /** 检查是否需要显示红点 */ export const checkRedDotShow = (id: RedDotID) => { let status = 0; if (id == RedDotID.无) return status; if (id == RedDotID.挂机页_扫荡) { let normalCount = gg.data.getStatistics(StatisticsType.saodangNormalCount) status = normalCount < gg.game.getMaxFreeSweepTimes() ? 1 : 0; } if (id == RedDotID.主界面_任务) { let newFunData = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 5); let isUnlocked = newFunData ? newFunData.chapter < gg.data.doc.chapter : false; return (isUnlocked && gg.data.checkTaskRewardGetData()) ? 1 : 0; } if (id == RedDotID.主界面_签到) { let signData = gg.data.getStringData(OtherDataType.SignData) let curSignStatus = Number(signData.split('&')[1]) return curSignStatus == 0 ? 1 : 0; } if (id == RedDotID.主界面_武器) { let isUnLock = gg.newFun.isUnLockMainPageTab(UIID.Weapon) let isCanUpgradeWeapon = gg.data.getIsCanUpgradeWeapon(); return (isCanUpgradeWeapon && isUnLock) ? 1 : 0; } if (id == RedDotID.主界面_角色) { let can = gg.data.getIsCanUpgradeWeaponByMoney(); let isUnlocked = gg.newFun.isUnLockMainPageTab(UIID.Role); return (can && isUnlocked) ? 1 : 0; } if (id == RedDotID.主界面_关卡) { let isCanGetBox = gg.data.project.isCanGetLevelBox(); return isCanGetBox ? 1 : 0; } if (id == RedDotID.主界面_离线收益) { let normalCount = gg.data.getStatistics(StatisticsType.saodangNormalCount); if(normalCount >= gg.game.getMaxFreeSweepTimes()){ //没有扫荡次数 判断是否超过1小时可以领取奖励 let lastAddTime = gg.data.getStatistics(StatisticsType.AfkRewards); let curTime = gg.data.getCurentTime(); let time = Math.floor((curTime - lastAddTime) / 1000); return time >= 3600 ? 1 : 0; }else{ //有扫荡次数 return normalCount < gg.game.getMaxFreeSweepTimes() ? 1 : 0; } } if (id == RedDotID.主界面_超值赠礼) { let greatGiftStatus = gg.data.getStatistics(StatisticsType.GreatGiftStatus) let greatGiftGetDay = gg.data.getStatistics(StatisticsType.GreatGiftGetDay) if(greatGiftStatus == 0 && greatGiftGetDay <= 2){ return 1 } return 0 } if (id == RedDotID.主界面_基金收益) { } if (id == RedDotID.主界面_月卡充值) { } if (id == RedDotID.主界面_邀请有礼) { } if (id == RedDotID.主界面_每日礼包) { } if (id == RedDotID.主界面_首充礼包) { } if (id == RedDotID.主界面_左章节红点) { let have = gg.data.project.isCanGetBoxBeforeOrAfter(gg.game.CurentSelectChapterId, gg.game.CurentSelectBattleDifficulty, true); return have ? 1 : 0; } if (id == RedDotID.主界面_右章节红点) { let have = gg.data.project.isCanGetBoxBeforeOrAfter(gg.game.CurentSelectChapterId, gg.game.CurentSelectBattleDifficulty, false); return have ? 1 : 0; } if (id == RedDotID.商店_免费钻石) { let isUnLock = gg.newFun.isUnLockMainPageTab(UIID.Shop) let count = gg.data.getStatistics(StatisticsType.ShopBuyItemAdCount) status = (count == 6 && isUnLock) ? 1 : 0; } if (id == RedDotID.商店_稀有宝箱) { let isUnLock = gg.newFun.isUnLockMainPageTab(UIID.Shop) let xiyouBoxSpendNum = sdkConfig.isIAPVersion ? 3000 : 200; status = (gg.data.getDiamond() >= xiyouBoxSpendNum && isUnLock) ? 1 : 0; } if (id == RedDotID.商店_免费金币) { let isUnLock = gg.newFun.isUnLockMainPageTab(UIID.Shop) let freeSpendNum = gg.data.getStatistics(StatisticsType.ShopBuyGoldAdCount) status = (freeSpendNum == 6 && isUnLock) ? 1 : 0; } if(id == RedDotID.主界面_挂机){ //挂机收益 免费收益3次 累积收益 //农场 let curTime = gg.data.getCurentTime() let farmSaodangNormalCount = gg.data.getStatistics(StatisticsType.farmSaodangNormalCount) if(farmSaodangNormalCount < 3){ status = 1 return status; }else{ status = 0 } let lastAddTime = gg.data.getStatistics(StatisticsType.framAfkRewards); let time = Math.floor((curTime - lastAddTime) / 1000) //time大于一个小时 if(time >= 3600){ status = 1 return status; }else{ status = 0 } //工厂 let isUnLockHard = gg.newFun.isUnLockDifficult(ChapterDifficulty.Hard); if(isUnLockHard){ let factorySaodangNormalCount = gg.data.getStatistics(StatisticsType.factorySaodangNormalCount) if(factorySaodangNormalCount < 3){ status = 1 return status; }else{ status = 0 } let lastAddTime = gg.data.getStatistics(StatisticsType.factoryAfkRewards); let time = Math.floor((curTime - lastAddTime) / 1000) //time大于一个小时 if(time >= 3600){ status = 1 return status; }else{ status = 0 } } //矿场 let isUnLockHell = gg.newFun.isUnLockDifficult(ChapterDifficulty.Hell); if(isUnLockHell){ let mineSaodangNormalCount = gg.data.getStatistics(StatisticsType.mineSaodangNormalCount) if(mineSaodangNormalCount < 3){ status = 1 return status; }else{ status = 0 } let lastAddTime = gg.data.getStatistics(StatisticsType.mineAfkRewards); let time = Math.floor((curTime - lastAddTime) / 1000) //time大于一个小时 if(time >= 3600){ status = 1 return status; }else{ status = 0 } } } return status; } /** * 红点模块使用说明,新增红点步骤如下: * 1.在本文件最上面新增红点ID * 2.在DotConfig数组中新增红点配置 * 3.在checkRedDotShow函数中新增红点判断逻辑 * 4.将“first/prefab/dot.prefab” 红点预制件拖到要显示的UI按钮上 * 5.在RedDotComp组件中设置id属性为新增的红点ID * * 注意: * 1.配置中只需要配置父节点,没有父节点的红点直接配置为无 * 2.配置中的父红点id配置根据UI实际显示逻辑配置 * 3.type字段目前没有用,预留字段,后续有需要再用 * 4.checkRedDotShow函数中只需要实现末端红点是否要显示,也就是设计的显示逻辑中没有子红点的红点,红点系统会自动处理父节点显示情况 */ @ccclass('RedDotComp') export class RedDotComp extends Component { @property({ type: Enum(RedDotID) }) id: RedDotID = RedDotID.无; dotIcon: Node = null; protected onLoad(): void { this.dotIcon = this.node.find("icon"); this.dotIcon.active = false; } protected onEnable(): void { GEvent.Ins.on(GEvent.UpdateRedDotEvent, this.onUpdateDot, this); GEvent.Ins.on(GEvent.UpdateItemNum, this.checkRedDotShow, this); this.checkRedDotShow(); } protected onDisable(): void { GEvent.Ins.off(GEvent.UpdateRedDotEvent, this.onUpdateDot, this); GEvent.Ins.off(GEvent.UpdateItemNum, this.checkRedDotShow, this); } /** 更新红点显示 */ onUpdateDot() { let dot = gg.dot.getDotData(this.id); if (!dot || !this.dotIcon) return; this.dotIcon.active = dot.status > 0; } /** 检查红点显示 */ checkRedDotShow() { let status = checkRedDotShow(this.id); this.dotIcon.active = status > 0; } }