123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- import DataMgr from "../data/DataMgr";
- import { AwardType, EAdType } from "../data/Define";
- import UIBase from "../fgui/core/UIBase";
- import ui_SignNormal from "../fgui/res/game/ui_SignNormal";
- import ui_UISign from "../fgui/res/game/ui_UISign";
- import PlatMgr from "../game/PlatMgr";
- import Common from "../utils/Common";
- import { xGame } from "../xGame";
- import MoneyNode from "./item/MoneyNode";
- import SignMax from "./item/SignMax";
- import SignNormal from "./item/SignNormal";
- import GlobalManager from "../utils/GlobalManager";
- import JSBridgeUtils from "../utils/JSBridgeUtils";
- export default class UISign extends UIBase {
- public ui: ui_UISign;
- public signArr: Array<SignNormal>;
- public signMax: SignMax;
- //
- public curDayIndex: number = 0;
- public starX: number = 0;
- public moneyNode: MoneyNode;
- public constructor() {
- super();
- }
- protected onConstructor(): void {
- this.ui = ui_UISign.createInstance();
- this.contentPane = this.ui;
- this.isEject = false;
- //
- this.moneyNode = new MoneyNode(this.ui.moneyNode);
- this.addUIClick(this.ui.closeNode.closeBtn, this.closeSelf);
- //
- this.initSignItem();
- this.addUIClick(this.ui.normalBtn, this.normalGetAward);
- this.addUIClick(this.ui.againBtn, this.againGetAward);
- }
- public show(): void {
- super.show();
- this.ui.t0.play();
- this.playSecretaryIdle();
- this.updateSign();
- }
- initSignItem() {
- this.signArr = [];
- for (let index = 0; index < 6; index++) {
- let temp = new SignNormal(this.ui.myNode["day" + (index + 1)]);
- this.signArr.push(temp);
- }
- this.signMax = new SignMax(this.ui.myNode.day7);
- if (Moyu.isKs)
- this.ui.closeNode.closeBtn.x += 100;
- }
- updateSign() {
- //初始化签到状态
- let sameDay = xGame.common.judgeSameDay();
- let max = 7;
- this.curDayIndex = DataMgr.getSignData();
- //首次签到或者循环完毕后又开始新一轮签到
- if (!this.curDayIndex || (this.curDayIndex >= max && !sameDay)) this.curDayIndex = 0;
- if (!sameDay) {
- //未领取奖励
- this.ui.normalBtn.visible = true;
- this.ui.tipsNode.visible = false;
- this.ui.againBtn.visible = false;
- }
- else {
- //已经领取过奖励了
- this.ui.normalBtn.visible = false;
- //判断是否再次领取了奖励,并且该奖励只能是钻石或者金币
- let again = DataMgr.getExtraSign();
- let isCurrency = false;//是否是货币
- let index = this.curDayIndex;
- if (index == 0) index = 7;
- let award = cfgTable.signData[index].award;
- let num = award[0].split("-")[0];
- if (num == "1" || num == "2") isCurrency = true;
- //
- let showAgain = again == 0 && isCurrency;
- this.ui.againBtn.visible = showAgain;
- this.ui.tipsNode.visible = !showAgain;
- }
- //
- for (let index = 0; index < this.signArr.length; index++) {
- this.signArr[index].updateSelf(index, sameDay, this.curDayIndex);
- }
- this.signMax.updateSelf(max - 1, sameDay, this.curDayIndex);
- }
- playSecretaryIdle() {
- let parent = this.ui.secretary.displayObject;
- parent.destroyChildren();
- let xx = this.ui.secretary.width / 2
- let yy = this.ui.secretary.height;
- let scale = xGame.common.getSecretaryScale();
- let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
- // xGame.common.secretary.play(data, 1, true, parent);
- xGame.common.secretary.play(data, 0, true, parent);
- }
- closeSelf() {
- this.hide();
- }
- normalGetAward() {
- let sameDay = xGame.common.judgeSameDay();
- if (!sameDay) {
- let award = cfgTable.signData[this.curDayIndex + 1].award;
- let temp;
- let type;
- let num;
- let arr = [];
- for (let index = 0; index < award.length; index++) {
- temp = award[index].split("-");
- type = parseInt(temp[0]);
- num = parseInt(temp[1]);
- let awardType = new AwardType();
- awardType.num = num;
- awardType.type = type;
- arr.push(awardType);
- }
- xGame.common.getAward(arr, (watchVideo) => {
- //
- this.curDayIndex++;
- if (this.curDayIndex > 7) this.curDayIndex = 0;
- DataMgr.setSignData(this.curDayIndex);
- DataMgr.setSignTime(new Date().getTime());
- //
- if (watchVideo) {
- DataMgr.setExtraSign(1);
- Moyu.sendDataEvent("signIn1");
- }
- this.updateSign();
- });
- }
- }
- againGetAward() {
- Moyu.sendDataEvent("signIn2");
- // GlobalManager.instance.registerMethod('xxxxx',this.xxxxx);
- // JSBridgeUtils.instance.showRewardAd('xxxxx');
- console.log('zh:qjff_AD_for_uisign')
- if (Laya.Browser.onAndroid) {
- let boo = JSBridgeUtils.instance.getNetworkAvailable();
- if (!boo) {
- JSBridgeUtils.instance.showToast2("Network error, reward unavailable");
- return;
- }
- }
- if (JSBridgeUtils.instance.showRewardAd('qjff_AD_for_uisign')) {
- } else {
- console.log('zh:AD 失败,直接发放奖励')
- this.qjff_AD_for_uisign();
- }
- //Moyu.showVideoAd(() => {
- // //
- // //已经领取了奖励的情况
- // let index = this.curDayIndex;
- // if (index == 0) index = 7;
- // let award = cfgTable.signData[index].award;
- // let temp;
- // let type;
- // let num;
- // for (let index = 0; index < award.length; index++) {
- // temp = award[index].split("-");
- // type = parseInt(temp[0]);
- // num = parseInt(temp[1]) * 3;//三倍再次领取所有奖励
- // xGame.common.playObjFlyAnim(num, type);
- // }
- // //
- // DataMgr.setExtraSign(1);
- // this.updateSign();
- // //
- //}, EAdType.againSign)
- }
- public qjff_AD_for_uisign() {
- //已经领取了奖励的情况
- let index = this.curDayIndex;
- if (index == 0) index = 7;
- let award = cfgTable.signData[index].award;
- let temp;
- let type;
- let num;
- for (let index = 0; index < award.length; index++) {
- temp = award[index].split("-");
- type = parseInt(temp[0]);
- num = parseInt(temp[1]) * 3;//三倍再次领取所有奖励
- xGame.common.playObjFlyAnim(num, type);
- }
- //
- DataMgr.setExtraSign(1);
- this.updateSign();
- }
- }
- UISign.uiName = "UISign";
|