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/mx/module/redDot/RedDotComp.ts

220 lines
8.9 KiB

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 { UIID } from 'db://assets/script/game/ConfigRes';
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,
//挂机页面红点
挂机页_扫荡 = 201,
挂机页_领取 = 202,
//商店红点
商店_免费钻石 = 301,
商店_稀有宝箱 = 302,
商店_免费金币 = 303,
}
/**
* 静态红点配置(动态生成的批量红点节点不建议走此配置,比如活动列表里生成的大量子节点红点)
*/
export const DotConfig: Array<Dot> = [//根据游戏修改此处配置
//主界面红点
{ 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.挂机页_领取) {
const lastAddTime = gg.data.getStatistics(StatisticsType.AfkRewards);
if (lastAddTime > 0) {
const time = Math.floor((gg.data.getCurentTime() - lastAddTime) / 1000);
status = time >= gg.game.afkTimeOne ? 1 : 0;
}
}
if (id == RedDotID.主界面_任务) {
return 0;
}
if (id == RedDotID.主界面_基金收益) {
}
if (id == RedDotID.主界面_月卡充值) {
}
if (id == RedDotID.主界面_邀请有礼) {
}
if (id == RedDotID.主界面_每日礼包) {
}
if (id == RedDotID.主界面_首充礼包) {
}
// if (id == RedDotID.主界面_左章节红点) {
// let r = gg.data.project.isCanGetBoxBeforeOrAfter(gg.game.CurentSelectChapterId, gg.game.CurentSelectBattleDifficulty, true);
// return r.boxCount > 0 ? 1 : 0;
// }
// if (id == RedDotID.主界面_右章节红点) {
// let r = gg.data.project.isCanGetBoxBeforeOrAfter(gg.game.CurentSelectChapterId, gg.game.CurentSelectBattleDifficulty, false);
// return r.boxCount > 0 ? 1 : 0;
// }
if (id == RedDotID.商店_免费钻石) {
let count = gg.data.getStatistics(StatisticsType.ShopBuyItemAdCount)
status = count == 6 ? 1 : 0;
}
if (id == RedDotID.商店_稀有宝箱) {
let xiyouBoxSpendNum = sdkConfig.isIAPVersion ? 3000 : 200;
status = gg.data.getDiamond() >= xiyouBoxSpendNum ? 1 : 0;
}
if (id == RedDotID.商店_免费金币) {
let freeSpendNum = gg.data.getStatistics(StatisticsType.ShopBuyGoldAdCount)
status = freeSpendNum == 6 ? 1 : 0;
}
if (id == RedDotID.主界面_武器) {
// 宝石库:有可合成宝石时显示
return gg.gem.canFuseAny() ? 1 : 0;
}
if (id == RedDotID.主界面_挂机) {
// 挂机收益页:免费扫荡 + 累积满 1 小时可领(StatisticsType.AfkRewards / UIwipeOut)
const normalCount = gg.data.getStatistics(StatisticsType.saodangNormalCount);
if (normalCount < gg.game.getMaxFreeSweepTimes()) {
return 1;
}
const lastAddTime = gg.data.getStatistics(StatisticsType.AfkRewards);
if (lastAddTime > 0) {
const time = Math.floor((gg.data.getCurentTime() - lastAddTime) / 1000);
if (time >= gg.game.afkTimeOne) {
return 1;
}
}
return 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;
}
}