大侠
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.
 
 
 

327 lines
12 KiB

import { PREVIEW } from "cc/env";
import { RedNotice } from "./RedNotice";
import { EGlobalEvent } from "../MesEvent/EGlobalEvent";
import { BAGGUIRedEnum, GFGUIRedEnum, HomeUIRedEnum, MainRedEnum, TZGUIRedEnum } from "./RedEnumType";
import MesMgr from "../MesEvent/MesMgr";
import { LocalDataMgr } from "../Mgr_LocalData/LocalDataMgr";
import { EGongFaType } from "../const/GameEnum";
import WuGongData from "../const/WuGongData";
import { Global } from "../Global";
/** 红点逻辑处理
* 枚举获取-> 更新的红点
*
*
*/
export interface redinfo{
show:boolean,
count:number
}
export default class RedPointLogic{
private static _EnumKeyValue = {};
static KeyEnumValue(type:any[], value) {
let key = RedPointLogic.getkey(type);
this._EnumKeyValue[key] = value;
}
/**红点逻辑 */
static mapRedLogic: Map<string, (arg?:any,isNoPop?:boolean) => redinfo> = new Map();
/**红点返回值 */
static mapRedcache: Map<string, redinfo> = new Map();
public static getkey(type:any[]) {
let key = "";
for (let i = 0; i < type.length; i++) {
const element = type[i];
if(!element){
continue;
}
key += `${element}_`;
}
return key;
}
static GetEnumKeyValue(type: any[]) {
let key = RedPointLogic.getkey(type)
return this._EnumKeyValue[key]
}
private static _init:boolean =false;
static init(){
if (this._init) { return }
this._init = true;
this.RegisterEnumRed();
this.addEvent();
}
/**
* 数据更新
* @param type
* @returns
*/
static DataUpdates(type:any[],arg?:any,isNoPop:boolean = false): redinfo {
let tempInfo = { show: false, count: 0 };
let key = RedPointLogic.getkey(type);
if (this.mapRedLogic.has(key)) {
let fun = this.mapRedLogic.get(key);
let red = fun(arg,isNoPop);
this.mapRedcache.set(key, red);
!isNoPop && RedNotice.emit(key, red);
tempInfo = red;
}
/**通知底层事件的同时通知 上层事件 */
if (type.length > 1 && !isNoPop) {
type.pop();
this.DataUpdates(type,arg,isNoPop);
}
return tempInfo;
}
/**
* 获取红点信息
* @param type 类型结构
* @returns
*/
static getRed(type: any[], arg?: any, isNoPop: boolean = false) {
let key = RedPointLogic.getkey(type)
if (this.mapRedcache.has(key)) {
return this.mapRedcache.get(key);
} else {
return this.DataUpdates(type, arg, isNoPop);
}
}
/**
* 合成数据
* 将红点信息 整理
*/
static compoundredinfo(info:redinfo[]):redinfo{
let tempInfo = { show: false, count: 0 };
for (let i = 0; i < info.length; i++) {
const element = info[i];
if(element){
tempInfo.count += element.count;
tempInfo.show = tempInfo.show || element.show;
}
}
tempInfo.show = (tempInfo.count > 0 || tempInfo.show);
return tempInfo;
}
/**注册 红点 */
static RegisterEnumRed() {
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法]), this.GongFaUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法,GFGUIRedEnum.剑]), this.GFJianUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法,GFGUIRedEnum.棍]), this.GFQiangUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法,GFGUIRedEnum.刀]), this.GFDaoUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法,GFGUIRedEnum.轻]), this.GFQingUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.功法,GFGUIRedEnum.内]), this.GFNeiUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.投资]), this.TouZiUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.投资,TZGUIRedEnum.茶馆升级]), this.ChaGuanUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.投资,TZGUIRedEnum.酒楼升级]), this.JiuLouUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.投资,TZGUIRedEnum.钱庄升级]), this.QianZhuangUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.游历]), this.HomeUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.游历,HomeUIRedEnum.离线奖励]), this.OffLineUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.游历,HomeUIRedEnum.签到]), this.SigninUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.游历,HomeUIRedEnum.任务完成]), this.TaskUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.游历,HomeUIRedEnum.打开公告]), this.NoticeUI.bind(this));
this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.包裹]), this.BagUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.包裹,BAGGUIRedEnum.典籍]), this.BookUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.包裹,BAGGUIRedEnum.材料]), this.MatUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.包裹,BAGGUIRedEnum.特殊]), this.SpecialUI.bind(this));
// this.mapRedLogic.set(RedPointLogic.getkey([MainRedEnum.包裹,BAGGUIRedEnum.装备]), this.EquipUI.bind(this));
}
private static addEvent(){
/**@需要实现 注册监听 */
MesMgr.on(EGlobalEvent.E_UPDATE_TOKEN,this.UpdateCoinRed,this);
MesMgr.on(EGlobalEvent.ITEM_UPDATE, this.UpdateBagRed, this);
RedNotice.on(EGlobalEvent.E_RED_UPDATE,this.DataUpdates,this);
}
private static UpdateCoinRed() {
this.DataUpdates([MainRedEnum.功法])
this.DataUpdates([MainRedEnum.投资])
}
private static UpdateBagRed() {
this.DataUpdates([MainRedEnum.包裹])
}
//#region 功法
private static GongFaUI(){
let tempInfo = { show: false, count: 0 };
for(let i = EGongFaType.剑法; i <= EGongFaType.内功; i++){
const res = LocalDataMgr.Role.canUpgradeByType(i);
if (res) {
tempInfo.show = true;
return tempInfo;
}
}
return tempInfo;
// let tempInfo = { show: false, count: 0 };
// tempInfo.show = this.GFJianUI().show || this.GFQiangUI().show || this.GFDaoUI().show || this.GFQingUI().show || this.GFNeiUI().show;
}
// private static GFJianUI(){
// const wglist:WuGongData[] = LocalDataMgr.Role.wugongs[EGongFaType.剑法];
// let tempInfo = { show: false, count: 0 };
// for (let i = 0; i < wglist.length; i++) {
// const uplvres = LocalDataMgr.Role.canUpgrade(EGongFaType.剑法, wglist[i].id);
// if (uplvres.res) {
// tempInfo.show = true;
// break;
// }
// }
// return tempInfo;
// }
// private static GFQiangUI(){
// const wglist:WuGongData[] = LocalDataMgr.Role.wugongs[EGongFaType.枪法];
// let tempInfo = { show: false, count: 0 };
// for (let i = 0; i < wglist.length; i++) {
// const uplvres = LocalDataMgr.Role.canUpgrade(EGongFaType.枪法, wglist[i].id);
// if (uplvres.res) {
// tempInfo.show = true;
// break;
// }
// }
// return tempInfo;
// }
// private static GFDaoUI(){
// const wglist:WuGongData[] = LocalDataMgr.Role.wugongs[EGongFaType.刀法];
// let tempInfo = { show: false, count: 0 };
// for (let i = 0; i < wglist.length; i++) {
// const uplvres = LocalDataMgr.Role.canUpgrade(EGongFaType.刀法, wglist[i].id);
// if (uplvres.res) {
// tempInfo.show = true;
// break;
// }
// }
// return tempInfo;
// }
// private static GFQingUI(){
// const wglist:WuGongData[] = LocalDataMgr.Role.wugongs[EGongFaType.轻功];
// let tempInfo = { show: false, count: 0 };
// for (let i = 0; i < wglist.length; i++) {
// const uplvres = LocalDataMgr.Role.canUpgrade(EGongFaType.轻功, wglist[i].id);
// if (uplvres.res) {
// tempInfo.show = true;
// break;
// }
// }
// return tempInfo;
// }
// private static GFNeiUI(){
// const wglist:WuGongData[] = LocalDataMgr.Role.wugongs[EGongFaType.内功];
// let tempInfo = { show: false, count: 0 };
// for (let i = 0; i < wglist.length; i++) {
// const uplvres = LocalDataMgr.Role.canUpgrade(EGongFaType.内功, wglist[i].id);
// if (uplvres.res) {
// tempInfo.show = true;
// break;
// }
// }
// return tempInfo;
// }
//#endregion
//#region 投资
private static TouZiUI(){
return { show: LocalDataMgr.Build.hasUpgradeBuilding(), count: 0 };
// return this.compoundredinfo(
// [
// this.getRed([MainRedEnum.投资, TZGUIRedEnum.茶馆升级], null, true),
// this.getRed([MainRedEnum.投资, TZGUIRedEnum.酒楼升级], null, true),
// this.getRed([MainRedEnum.投资, TZGUIRedEnum.钱庄升级], null, true)
// ]
// )
}
// private static ChaGuanUI(){
// return { show: false, count: 0 };
// }
// private static JiuLouUI(){
// return {show: false, count: 0};
// }
// private static QianZhuangUI(){
// return {show: false, count: 0};
// }
//#endregion
//#region 游历
private static HomeUI(){
return this.compoundredinfo(
[
this.getRed([MainRedEnum.游历, HomeUIRedEnum.离线奖励], null, true),
this.getRed([MainRedEnum.游历, HomeUIRedEnum.签到], null, true),
this.getRed([MainRedEnum.游历, HomeUIRedEnum.任务完成], null, true),
this.getRed([MainRedEnum.游历, HomeUIRedEnum.打开公告], null, true),
]
)
}
private static OffLineUI(){
return { show: LocalDataMgr.Date.getRedShow(), count: 0 };
}
private static SigninUI(){
return {show: LocalDataMgr.Signin.hasAward, count: 0};
}
private static TaskUI(){
return {show: LocalDataMgr.Task.task.complete, count: 0};
}
private static NoticeUI(){
const notice = Global.CsvMgr.GetNoticeData();
const isShow = (notice && LocalDataMgr.Game.NoticeDays < notice.timenum);
return {show: isShow, count: 0};
}
//#endregion
//#region 商店
private static ShopUI(){
return {show: false, count: 0};
}
//#endregion
//#region 背包
private static BagUI(){
const show = LocalDataMgr.Bag.hasNewItem();
return { show: show, count: 0 };
// return this.compoundredinfo(
// [
// this.getRed([MainRedEnum.包裹, BAGGUIRedEnum.典籍], null, true),
// this.getRed([MainRedEnum.包裹, BAGGUIRedEnum.材料], null, true),
// this.getRed([MainRedEnum.包裹, BAGGUIRedEnum.特殊], null, true),
// this.getRed([MainRedEnum.包裹, BAGGUIRedEnum.装备], null, true)
// ]
// )
}
private static BookUI(){
return { show: false, count: 0 };
}
private static MatUI(){
return {show: false, count: 0};
}
private static SpecialUI(){
return {show: false, count: 0};
}
private static EquipUI(){
return {show: false, count: 0};
}
//#endregion
}
if (PREVIEW) {
window['MainRedLogicData'] = RedPointLogic;
}
RedPointLogic.KeyEnumValue([MainRedEnum.功法],GFGUIRedEnum);
RedPointLogic.KeyEnumValue([MainRedEnum.游历],HomeUIRedEnum);
// MainRedLogicData.KeyEnumValue([MainRedEnum.农田], FROMUIRedEnum)