import DataMgr from "../../data/DataMgr"; import ui_UIMoyu from "../../fgui/res/loading/ui_UIMoyu"; import { xGame } from "../../xGame"; export default class MoyuMgr { public static moyuView: MoyuView public static isAdvise: boolean = false; public static initMoyu() { this.moyuView = new MoyuView(); Laya.stage.addChild(this.moyuView.ui.displayObject); this.moyuView.ui.x = (Laya.stage.width - 1334) / 2; this.moyuView.ui.displayObject.zOrder = 1000; this.moyuView.init(); //显示全屏的健康忠告 this.moyuView.showTip(true); //显示适龄提示(位置) this.moyuView.showAge(true, 0, Laya.stage.height - 320); window['XApk'] = this; } public static showAge(show) { if (this.moyuView) this.moyuView.showAge(show); } public static onPlatMsg(idx: string) { if (!MoyuMgr.moyuView) return; if (idx == '0') { MoyuMgr.moyuView.showTip(false); } } /** * 隐私授权 * @param call 授权成功回调 */ public static showAgree(call: Function) { if (this.moyuView) this.moyuView.showAgree(call); else call && call(); } /** * 1=隐私协议,2用户协议 * @param type 协议类别 */ public static showXy(type = 1) { if (this.moyuView) this.moyuView.showXy(type); } } class MoyuView { //private tipActive:boolean=false; private agreeCall: Function; private ysxyNum = 1; private ysJson = null; public ui: ui_UIMoyu; // constructor() { this.ui = ui_UIMoyu.createInstance(); } public init() { this.ui.mainBg.visible = false; this.ui.xyNode.visible = false; this.ui.ageNode.visible = false; this.ui.tipNode.visible = false; this.ui.rnNode.visible = false; this.ui.fcmNode.visible = false; this.ui.ageTip.visible = false; this.ui.msgNode.visible = false; this.ui.visible = false; this.ui.xyNode.xyList.setVirtual(); this.ui.xyNode.xyList.itemRenderer = Laya.Handler.create(this, this.renderListItem, null, false); this.ui.ageNode.btnAge.onClick(this, this.onClick, [this.ui.ageNode.btnAge]); this.ui.tipNode.onClick(this, this.onClick, [this.ui.tipNode]); this.ui.ageTip.onClick(this, this.onClick, [this.ui.ageTip]); this.ui.xyNode.btnKnown.visible = false; this.ui.xyNode.xy1.visible = false; this.ui.xyNode.xy2.visible = false; this.ui.xyNode.btnXy1.visible = this.ui.xyNode.btnXy2.visible = false; this.ui.xyNode.btnSure.visible = this.ui.xyNode.btnXy3.visible = false; this.ui.xyNode.btnXy1.onClick(this, this.onClick, [this.ui.xyNode.btnXy1]); this.ui.xyNode.btnXy2.onClick(this, this.onClick, [this.ui.xyNode.btnXy2]); this.ui.xyNode.btnXy3.onClick(this, this.onClick, [this.ui.xyNode.btnXy3]); this.ui.xyNode.btnNo.onClick(this, this.onClick, [this.ui.xyNode.btnNo]); this.ui.xyNode.btnYes.onClick(this, this.onClick, [this.ui.xyNode.btnYes]); this.ui.xyNode.btnSure.onClick(this, this.onClick, [this.ui.xyNode.btnSure]); this.ui.xyNode.btnBack.onClick(this, this.onClick, [this.ui.xyNode.btnBack]); this.ui.xyNode.btnKnown.onClick(this, this.onClick, [this.ui.xyNode.btnKnown]); this.ui.rnNode.btnExit.onClick(this, this.onClick, [this.ui.rnNode.btnExit]); this.ui.rnNode.btnCheck.onClick(this, this.onClick, [this.ui.rnNode.btnCheck]); this.ui.rnNode.btnDone.onClick(this, this.onClick, [this.ui.rnNode.btnDone]); this.ui.fcmNode.btnRn.onClick(this, this.onClick, [this.ui.fcmNode.btnRn]); if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isTTApk || Moyu.isOppo || Moyu.isVivo) { this.ysxyNum = 2; } } onClick(obj) { xGame.soundMgr.playSound(xGame.common.btnClickStr); //console.log(obj); switch (obj) { case this.ui.ageTip: if (Moyu.isTTApk) { this.ui.ageNode.visible = true; this.ui.mainBg.visible = true; } break; case this.ui.tipNode: this.showTip(false); break; case this.ui.ageNode.btnAge: this.ui.ageNode.visible = false; this.ui.mainBg.visible = false; if (!this.ui.xyNode.visible && !this.ui.rnNode.visible) this.ui.visible = false; break; case this.ui.xyNode.btnXy3: case this.ui.xyNode.btnXy1: this.loadXy(1); break; case this.ui.xyNode.btnXy2: this.loadXy(2); break; case this.ui.xyNode.btnBack: this.ui.xyNode.xy1.visible = true; this.ui.xyNode.xy2.visible = false; break; case this.ui.xyNode.btnKnown: this.ui.xyNode.visible = false; this.ui.mainBg.visible = false; this.ui.visible = false; break; case this.ui.rnNode.btnCheck: this.check(); break; case this.ui.rnNode.btnExit: case this.ui.xyNode.btnNo: this.ysxyNum--; if (this.ysxyNum > 0) this.showMsg("Refuse to quit the game once again")//再次拒绝退出游戏 else { Moyu.userAgree(false); Moyu.exit(); } break; case this.ui.xyNode.btnSure: case this.ui.xyNode.btnYes: DataMgr.userData.isAgree = true; DataMgr.saveUserData(); this.onAgree(); break; case this.ui.rnNode.btnDone: this.ui.rnNode.visible = false; this.ui.visible = false; break; case this.ui.fcmNode.btnRn: this.showRn(); break; } } public showTip(show: boolean) { //目前只有这2个需求显示全屏健康忠告 if (!Moyu.isVVApk && !Moyu.isOPApk) return; if (show) { MoyuMgr.isAdvise = true; this.ui.visible = true; this.ui.tipNode.visible = true; this.ui.tipNode.alpha = 1; Laya.timer.once(1000, this, this.showTip, [false]); } else// if(this.tipActive) { this.ui.tipNode.alpha = 1; this.ui.tipNode.visible = true; Laya.Tween.to(this.ui.tipNode, { alpha: 0 }, 500, null, Laya.Handler.create(this.ui, () => { this.ui.tipNode.visible = false; MoyuMgr.isAdvise = false; }), 1000); } // console.log("showTip"+show); // this.tipActive=show; } public showAge(show: boolean, px: number = 0, py: number = 0) { if (Moyu.platType > 10 && !Moyu.isIos) //非小游戏 { this.ui.ageTip.x = px; this.ui.ageTip.y = py; this.ui.ageTip.visible = show; if (show) this.ui.visible = true; } } public showAgree(call: Function) { this.agreeCall = call; // this.onAgree(); return if (Moyu.hasAgree && !DataMgr.userData.isAgree && !Moyu.isIos) { this.showXy(0); } else this.onAgree(); } onAgree() { if (!this.ui.ageNode.visible) this.ui.visible = false; this.ui.xyNode.visible = false; Moyu.userAgree(true); this.showAge(false); this.agreeCall && this.agreeCall(); this.showRn(); } public showMsg(txt: string) { //console.log(txt); this.ui.msgNode.txtMsg.text = txt; this.ui.msgNode.visible = true; this.ui.msgNode.alpha = 1; this.ui.visible = true; Laya.Tween.to(this.ui.msgNode, { alpha: 0 }, 600, null, Laya.Handler.create(this.ui, () => { this.ui.msgNode.visible = false; }), 2500, true); } /** * 需要启用摸鱼的防沉迷和实名认证 */ showRn() { //实名平台 if (Moyu.isTTApk || Moyu.isPlat(MoyuPlat.hhw)) { if (!Moyu.isRealName || Moyu.gameTime < 999) { this.ui.rnNode.rn1.visible = true; this.ui.rnNode.rn2.visible = false; this.ui.rnNode.rn3.visible = false; this.ui.rnNode.rn4.visible = false; this.ui.rnNode.visible = true; this.ui.mainBg.visible = true; this.ui.rnNode.btnDone.visible = false; this.ui.rnNode.btnExit.visible = true; this.ui.rnNode.btnCheck.visible = true; this.ui.fcmNode.visible = false; this.ui.visible = true; return; } } this.showFcm(); } showFcm() { //防沉迷平台 if (Moyu.isTTApk || Moyu.isPlat(MoyuPlat.hhw)) { Moyu.initFCM(true); if (Moyu.gameTime < 1) this.fcmLoop(); else if (Moyu.gameTime < 999) Laya.timer.loop(10000, this.ui, this.fcmLoop) } } fcmLoop() { if (Moyu.gameTime < 1) { this.ui.rnNode.visible = false; this.ui.fcmNode.visible = true; this.ui.mainBg.visible = true; this.ui.visible = true; this.ui.fcmNode.btnRn.visible = !Moyu.isLegal; Laya.timer.clear(this.ui, this.fcmLoop); } } check() { if (this.ui.rnNode.rn2.visible || this.ui.rnNode.rn1.visible) { this.ui.rnNode.rn1.visible = false; this.ui.rnNode.rn2.visible = false; this.ui.rnNode.rn4.visible = true; } else if (this.ui.rnNode.rn4.visible) { let name = this.ui.rnNode.inputName.text; let code = this.ui.rnNode.inputCode.text; if (code && code.length == 18) { this.ui.rnNode.rn1.visible = false; this.ui.rnNode.rn4.visible = false; Moyu.authenticate(name, code, (res: boolean) => { this.ui.rnNode.rn2.visible = !res; this.ui.rnNode.rn3.visible = res; this.ui.rnNode.btnDone.visible = res; this.ui.rnNode.btnExit.visible = !res; this.ui.rnNode.btnCheck.visible = !res; if (res) this.showFcm(); }); } else this.showMsg("信息填写不完整"); } } loadXy(type = 0) { this.ui.xyNode.xy1.visible = false; this.ui.xyNode.xy2.visible = true; this.ui.xyNode.xyList.scrollToView(0); //this.ui.xyNode.xyList.displayObject.destroyChildren(); if (type == 1) { // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo) // Laya.loader.load("app/xy/ovxy.json", Laya.Handler.create(this, this.createXY)); // else Laya.loader.load("app/xy/yiiwan_ys.json", Laya.Handler.create(this, this.createXY)); } else if (type == 2) { Laya.loader.load("app/xy/yiiwan_yh.json", Laya.Handler.create(this, this.createXY)); } } public showXy(type = 0) { this.xyBtn(); if (type == 0) //load界面 { if (Moyu.isPlat(MoyuPlat.f399Apk)) { this.ui.xyNode.btnSure.visible = true; } else { this.ui.xyNode.btnYes.visible = true; this.ui.xyNode.btnNo.visible = true; } } else //再显示 { this.ui.xyNode.btnKnown.visible = true; //this.loadXy(type); this.ui.mainBg.visible = true; } this.ui.xyNode.xy1.visible = true; this.ui.xyNode.xy2.visible = false; this.ui.xyNode.visible = true; this.ui.visible = true; } xyBtn() { this.ui.xyNode.btnSure.visible = false; this.ui.xyNode.btnYes.visible = false; this.ui.xyNode.btnNo.visible = false; this.ui.xyNode.btnKnown.visible = false; // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo) // { // this.ui.btnXy3.visible=true; // this.ui.btnXy2.visible=false; // this.ui.btnXy1.visible=false; // this.ui.xy1.text = "欢迎来到《》"; // } // else { this.ui.xyNode.btnXy3.visible = false; this.ui.xyNode.btnXy2.visible = true; this.ui.xyNode.btnXy1.visible = true; this.ui.xyNode.xy1.text = "Welcome to《8Ball Fury》"; } } createXY(json) { this.ysJson = json.content; // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo) // this.ui.txtTitle.text = json.title.replace('GAMENAME', "万宁象棋大招版"); // else this.ui.xyNode.txtTitle.text = json.title.replace('GAMENAME', "8Ball Fury");//万宁台球 this.ui.xyNode.xyList.numItems = this.ysJson.length; this.ui.xyNode.xy2.visible = true; } renderListItem(idx, cell) { //console.log(idx); let xy = this.ysJson[idx]; cell.height = xy.line * 30; cell.xyItem.text = xy.text; } onDestroy() { this.agreeCall = null; } }