MoyuMgr.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import DataMgr from "../../data/DataMgr";
  2. import ui_UIMoyu from "../../fgui/res/loading/ui_UIMoyu";
  3. import { xGame } from "../../xGame";
  4. export default class MoyuMgr {
  5. public static moyuView: MoyuView
  6. public static isAdvise: boolean = false;
  7. public static initMoyu() {
  8. this.moyuView = new MoyuView();
  9. Laya.stage.addChild(this.moyuView.ui.displayObject);
  10. this.moyuView.ui.x = (Laya.stage.width - 1334) / 2;
  11. this.moyuView.ui.displayObject.zOrder = 1000;
  12. this.moyuView.init();
  13. //显示全屏的健康忠告
  14. this.moyuView.showTip(true);
  15. //显示适龄提示(位置)
  16. this.moyuView.showAge(true, 0, Laya.stage.height - 320);
  17. window['XApk'] = this;
  18. }
  19. public static showAge(show) {
  20. if (this.moyuView)
  21. this.moyuView.showAge(show);
  22. }
  23. public static onPlatMsg(idx: string) {
  24. if (!MoyuMgr.moyuView)
  25. return;
  26. if (idx == '0') {
  27. MoyuMgr.moyuView.showTip(false);
  28. }
  29. }
  30. /**
  31. * 隐私授权
  32. * @param call 授权成功回调
  33. */
  34. public static showAgree(call: Function) {
  35. if (this.moyuView)
  36. this.moyuView.showAgree(call);
  37. else
  38. call && call();
  39. }
  40. /**
  41. * 1=隐私协议,2用户协议
  42. * @param type 协议类别
  43. */
  44. public static showXy(type = 1) {
  45. if (this.moyuView)
  46. this.moyuView.showXy(type);
  47. }
  48. }
  49. class MoyuView {
  50. //private tipActive:boolean=false;
  51. private agreeCall: Function;
  52. private ysxyNum = 1;
  53. private ysJson = null;
  54. public ui: ui_UIMoyu;
  55. //
  56. constructor() {
  57. this.ui = ui_UIMoyu.createInstance();
  58. }
  59. public init() {
  60. this.ui.mainBg.visible = false;
  61. this.ui.xyNode.visible = false;
  62. this.ui.ageNode.visible = false;
  63. this.ui.tipNode.visible = false;
  64. this.ui.rnNode.visible = false;
  65. this.ui.fcmNode.visible = false;
  66. this.ui.ageTip.visible = false;
  67. this.ui.msgNode.visible = false;
  68. this.ui.visible = false;
  69. this.ui.xyNode.xyList.setVirtual();
  70. this.ui.xyNode.xyList.itemRenderer = Laya.Handler.create(this, this.renderListItem, null, false);
  71. this.ui.ageNode.btnAge.onClick(this, this.onClick, [this.ui.ageNode.btnAge]);
  72. this.ui.tipNode.onClick(this, this.onClick, [this.ui.tipNode]);
  73. this.ui.ageTip.onClick(this, this.onClick, [this.ui.ageTip]);
  74. this.ui.xyNode.btnKnown.visible = false;
  75. this.ui.xyNode.xy1.visible = false;
  76. this.ui.xyNode.xy2.visible = false;
  77. this.ui.xyNode.btnXy1.visible = this.ui.xyNode.btnXy2.visible = false;
  78. this.ui.xyNode.btnSure.visible = this.ui.xyNode.btnXy3.visible = false;
  79. this.ui.xyNode.btnXy1.onClick(this, this.onClick, [this.ui.xyNode.btnXy1]);
  80. this.ui.xyNode.btnXy2.onClick(this, this.onClick, [this.ui.xyNode.btnXy2]);
  81. this.ui.xyNode.btnXy3.onClick(this, this.onClick, [this.ui.xyNode.btnXy3]);
  82. this.ui.xyNode.btnNo.onClick(this, this.onClick, [this.ui.xyNode.btnNo]);
  83. this.ui.xyNode.btnYes.onClick(this, this.onClick, [this.ui.xyNode.btnYes]);
  84. this.ui.xyNode.btnSure.onClick(this, this.onClick, [this.ui.xyNode.btnSure]);
  85. this.ui.xyNode.btnBack.onClick(this, this.onClick, [this.ui.xyNode.btnBack]);
  86. this.ui.xyNode.btnKnown.onClick(this, this.onClick, [this.ui.xyNode.btnKnown]);
  87. this.ui.rnNode.btnExit.onClick(this, this.onClick, [this.ui.rnNode.btnExit]);
  88. this.ui.rnNode.btnCheck.onClick(this, this.onClick, [this.ui.rnNode.btnCheck]);
  89. this.ui.rnNode.btnDone.onClick(this, this.onClick, [this.ui.rnNode.btnDone]);
  90. this.ui.fcmNode.btnRn.onClick(this, this.onClick, [this.ui.fcmNode.btnRn]);
  91. if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isTTApk || Moyu.isOppo || Moyu.isVivo) {
  92. this.ysxyNum = 2;
  93. }
  94. }
  95. onClick(obj) {
  96. xGame.soundMgr.playSound(xGame.common.btnClickStr);
  97. //console.log(obj);
  98. switch (obj) {
  99. case this.ui.ageTip:
  100. if (Moyu.isTTApk) {
  101. this.ui.ageNode.visible = true;
  102. this.ui.mainBg.visible = true;
  103. }
  104. break;
  105. case this.ui.tipNode:
  106. this.showTip(false);
  107. break;
  108. case this.ui.ageNode.btnAge:
  109. this.ui.ageNode.visible = false;
  110. this.ui.mainBg.visible = false;
  111. if (!this.ui.xyNode.visible && !this.ui.rnNode.visible)
  112. this.ui.visible = false;
  113. break;
  114. case this.ui.xyNode.btnXy3:
  115. case this.ui.xyNode.btnXy1:
  116. this.loadXy(1);
  117. break;
  118. case this.ui.xyNode.btnXy2:
  119. this.loadXy(2);
  120. break;
  121. case this.ui.xyNode.btnBack:
  122. this.ui.xyNode.xy1.visible = true;
  123. this.ui.xyNode.xy2.visible = false;
  124. break;
  125. case this.ui.xyNode.btnKnown:
  126. this.ui.xyNode.visible = false;
  127. this.ui.mainBg.visible = false;
  128. this.ui.visible = false;
  129. break;
  130. case this.ui.rnNode.btnCheck:
  131. this.check();
  132. break;
  133. case this.ui.rnNode.btnExit:
  134. case this.ui.xyNode.btnNo:
  135. this.ysxyNum--;
  136. if (this.ysxyNum > 0)
  137. this.showMsg("Refuse to quit the game once again")//再次拒绝退出游戏
  138. else {
  139. Moyu.userAgree(false);
  140. Moyu.exit();
  141. }
  142. break;
  143. case this.ui.xyNode.btnSure:
  144. case this.ui.xyNode.btnYes:
  145. DataMgr.userData.isAgree = true;
  146. DataMgr.saveUserData();
  147. this.onAgree();
  148. break;
  149. case this.ui.rnNode.btnDone:
  150. this.ui.rnNode.visible = false;
  151. this.ui.visible = false;
  152. break;
  153. case this.ui.fcmNode.btnRn:
  154. this.showRn();
  155. break;
  156. }
  157. }
  158. public showTip(show: boolean) {
  159. //目前只有这2个需求显示全屏健康忠告
  160. if (!Moyu.isVVApk && !Moyu.isOPApk)
  161. return;
  162. if (show) {
  163. MoyuMgr.isAdvise = true;
  164. this.ui.visible = true;
  165. this.ui.tipNode.visible = true;
  166. this.ui.tipNode.alpha = 1;
  167. Laya.timer.once(1000, this, this.showTip, [false]);
  168. }
  169. else// if(this.tipActive)
  170. {
  171. this.ui.tipNode.alpha = 1;
  172. this.ui.tipNode.visible = true;
  173. Laya.Tween.to(this.ui.tipNode, { alpha: 0 }, 500, null, Laya.Handler.create(this.ui, () => {
  174. this.ui.tipNode.visible = false;
  175. MoyuMgr.isAdvise = false;
  176. }), 1000);
  177. }
  178. // console.log("showTip"+show);
  179. // this.tipActive=show;
  180. }
  181. public showAge(show: boolean, px: number = 0, py: number = 0) {
  182. if (Moyu.platType > 10 && !Moyu.isIos) //非小游戏
  183. {
  184. this.ui.ageTip.x = px;
  185. this.ui.ageTip.y = py;
  186. this.ui.ageTip.visible = show;
  187. if (show)
  188. this.ui.visible = true;
  189. }
  190. }
  191. public showAgree(call: Function) {
  192. this.agreeCall = call;
  193. //
  194. this.onAgree();
  195. return
  196. if (Moyu.hasAgree && !DataMgr.userData.isAgree && !Moyu.isIos) {
  197. this.showXy(0);
  198. }
  199. else
  200. this.onAgree();
  201. }
  202. onAgree() {
  203. if (!this.ui.ageNode.visible)
  204. this.ui.visible = false;
  205. this.ui.xyNode.visible = false;
  206. Moyu.userAgree(true);
  207. this.showAge(false);
  208. this.agreeCall && this.agreeCall();
  209. this.showRn();
  210. }
  211. public showMsg(txt: string) {
  212. //console.log(txt);
  213. this.ui.msgNode.txtMsg.text = txt;
  214. this.ui.msgNode.visible = true;
  215. this.ui.msgNode.alpha = 1;
  216. this.ui.visible = true;
  217. Laya.Tween.to(this.ui.msgNode, { alpha: 0 }, 600, null, Laya.Handler.create(this.ui, () => {
  218. this.ui.msgNode.visible = false;
  219. }), 2500, true);
  220. }
  221. /**
  222. * 需要启用摸鱼的防沉迷和实名认证
  223. */
  224. showRn() {
  225. //实名平台
  226. if (Moyu.isTTApk || Moyu.isPlat(MoyuPlat.hhw)) {
  227. if (!Moyu.isRealName || Moyu.gameTime < 999) {
  228. this.ui.rnNode.rn1.visible = true;
  229. this.ui.rnNode.rn2.visible = false;
  230. this.ui.rnNode.rn3.visible = false;
  231. this.ui.rnNode.rn4.visible = false;
  232. this.ui.rnNode.visible = true;
  233. this.ui.mainBg.visible = true;
  234. this.ui.rnNode.btnDone.visible = false;
  235. this.ui.rnNode.btnExit.visible = true;
  236. this.ui.rnNode.btnCheck.visible = true;
  237. this.ui.fcmNode.visible = false;
  238. this.ui.visible = true;
  239. return;
  240. }
  241. }
  242. this.showFcm();
  243. }
  244. showFcm() {
  245. //防沉迷平台
  246. if (Moyu.isTTApk || Moyu.isPlat(MoyuPlat.hhw)) {
  247. Moyu.initFCM(true);
  248. if (Moyu.gameTime < 1)
  249. this.fcmLoop();
  250. else if (Moyu.gameTime < 999)
  251. Laya.timer.loop(10000, this.ui, this.fcmLoop)
  252. }
  253. }
  254. fcmLoop() {
  255. if (Moyu.gameTime < 1) {
  256. this.ui.rnNode.visible = false;
  257. this.ui.fcmNode.visible = true;
  258. this.ui.mainBg.visible = true;
  259. this.ui.visible = true;
  260. this.ui.fcmNode.btnRn.visible = !Moyu.isLegal;
  261. Laya.timer.clear(this.ui, this.fcmLoop);
  262. }
  263. }
  264. check() {
  265. if (this.ui.rnNode.rn2.visible || this.ui.rnNode.rn1.visible) {
  266. this.ui.rnNode.rn1.visible = false;
  267. this.ui.rnNode.rn2.visible = false;
  268. this.ui.rnNode.rn4.visible = true;
  269. }
  270. else if (this.ui.rnNode.rn4.visible) {
  271. let name = this.ui.rnNode.inputName.text;
  272. let code = this.ui.rnNode.inputCode.text;
  273. if (code && code.length == 18) {
  274. this.ui.rnNode.rn1.visible = false;
  275. this.ui.rnNode.rn4.visible = false;
  276. Moyu.authenticate(name, code, (res: boolean) => {
  277. this.ui.rnNode.rn2.visible = !res;
  278. this.ui.rnNode.rn3.visible = res;
  279. this.ui.rnNode.btnDone.visible = res;
  280. this.ui.rnNode.btnExit.visible = !res;
  281. this.ui.rnNode.btnCheck.visible = !res;
  282. if (res)
  283. this.showFcm();
  284. });
  285. }
  286. else
  287. this.showMsg("信息填写不完整");
  288. }
  289. }
  290. loadXy(type = 0) {
  291. this.ui.xyNode.xy1.visible = false;
  292. this.ui.xyNode.xy2.visible = true;
  293. this.ui.xyNode.xyList.scrollToView(0);
  294. //this.ui.xyNode.xyList.displayObject.destroyChildren();
  295. if (type == 1) {
  296. // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo)
  297. // Laya.loader.load("app/xy/ovxy.json", Laya.Handler.create(this, this.createXY));
  298. // else
  299. Laya.loader.load("app/xy/yiiwan_ys.json", Laya.Handler.create(this, this.createXY));
  300. }
  301. else if (type == 2) {
  302. Laya.loader.load("app/xy/yiiwan_yh.json", Laya.Handler.create(this, this.createXY));
  303. }
  304. }
  305. public showXy(type = 0) {
  306. this.xyBtn();
  307. if (type == 0) //load界面
  308. {
  309. if (Moyu.isPlat(MoyuPlat.f399Apk)) {
  310. this.ui.xyNode.btnSure.visible = true;
  311. }
  312. else {
  313. this.ui.xyNode.btnYes.visible = true;
  314. this.ui.xyNode.btnNo.visible = true;
  315. }
  316. }
  317. else //再显示
  318. {
  319. this.ui.xyNode.btnKnown.visible = true;
  320. //this.loadXy(type);
  321. this.ui.mainBg.visible = true;
  322. }
  323. this.ui.xyNode.xy1.visible = true;
  324. this.ui.xyNode.xy2.visible = false;
  325. this.ui.xyNode.visible = true;
  326. this.ui.visible = true;
  327. }
  328. xyBtn() {
  329. this.ui.xyNode.btnSure.visible = false;
  330. this.ui.xyNode.btnYes.visible = false;
  331. this.ui.xyNode.btnNo.visible = false;
  332. this.ui.xyNode.btnKnown.visible = false;
  333. // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo)
  334. // {
  335. // this.ui.btnXy3.visible=true;
  336. // this.ui.btnXy2.visible=false;
  337. // this.ui.btnXy1.visible=false;
  338. // this.ui.xy1.text = "欢迎来到《》";
  339. // }
  340. // else
  341. {
  342. this.ui.xyNode.btnXy3.visible = false;
  343. this.ui.xyNode.btnXy2.visible = true;
  344. this.ui.xyNode.btnXy1.visible = true;
  345. this.ui.xyNode.xy1.text = "Welcome to《8Ball Fury》";
  346. }
  347. }
  348. createXY(json) {
  349. this.ysJson = json.content;
  350. // if (Moyu.isVVApk || Moyu.isOPApk || Moyu.isOppo || Moyu.isVivo)
  351. // this.ui.txtTitle.text = json.title.replace('GAMENAME', "万宁象棋大招版");
  352. // else
  353. this.ui.xyNode.txtTitle.text = json.title.replace('GAMENAME', "8Ball Fury");//万宁台球
  354. this.ui.xyNode.xyList.numItems = this.ysJson.length;
  355. this.ui.xyNode.xy2.visible = true;
  356. }
  357. renderListItem(idx, cell) {
  358. //console.log(idx);
  359. let xy = this.ysJson[idx];
  360. cell.height = xy.line * 30;
  361. cell.xyItem.text = xy.text;
  362. }
  363. onDestroy() {
  364. this.agreeCall = null;
  365. }
  366. }