import { _decorator, Component, Node, LabelComponent, Vec2, Vec3, view } from 'cc'; import { GUIManager } from '../../../engines/gui/GUIManager'; import { GUIMediator } from '../../../engines/gui/GUIMediator'; import { NoticeManager } from '../../../engines/notices/NoticeManager'; import { SceneManager } from '../../../engines/scenes/SceneManager'; import StringUtils from '../../../engines/utils/StringUtils'; import { LiangLiangSDK } from '../../../libs/liangliangSDK'; import { PlatformManager } from '../../../Platform/PlatformManager'; import { QQPlatform } from '../../../Platform/QQ/QQPlatform'; import { branchIdType } from '../../../Platform/WeChat/branchIdType'; import { WeChatPlatforms } from '../../../Platform/WeChat/WeChatPlatforms'; import GameConfigManager from '../../models/GameConfigManager'; import { GameModel } from '../../models/GameModel'; import { GameController } from '../fightings/GameController'; import { UIConst } from '../UIConst'; const { ccclass, property } = _decorator; @ccclass('GameOverMediator') export class GameOverMediator extends GUIMediator { @property(Node) WinGroup: Node = null; @property({ type: Node }) WinAwardNode: Node = null; @property({ type: LabelComponent }) WinAwardLabel: LabelComponent = null; @property({ type: Node }) DiamondAwardNode: Node = null; @property({ type: LabelComponent }) DiamondAwardLabel: LabelComponent = null; @property(Node) DefeatedGroup: Node = null; @property(Node) WinBackButton: Node = null; @property(Node) DefeatedBackButton: Node = null; private isWin: boolean; private award: number; private diamond: number; private buttonCkilcBool: boolean = false; private buttonClickIsOk: boolean = false; onLoad() { // PlatformManager.showBanner() } OnShow(data?: any): void { super.OnShow(data); this.isWin = data; this.WinGroup.active = this.isWin; this.DefeatedGroup.active = !this.isWin; this.buttonCkilcBool = false; this.buttonClickIsOk = false; PlatformManager.showBanner(); //胜利 if (this.isWin == true) { this.WinBackButton.active = false; this.scheduleOnce(() => { this.WinBackButton.active = true; }, 2); this.WinGroup.active = true; this.DefeatedGroup.active = false; let levelConfig: any = GameConfigManager.GetLevelConfig(GameModel.single.currentLevel - 1); //关卡基础奖励 this.award = levelConfig.awards + levelConfig.killAward * GameModel.single.killCount; //金币奖励 this.WinAwardLabel.string = "X" + StringUtils.numberUtilsEn(this.award, 0); //钻石奖励 if (levelConfig.diamondRewards > 0) { this.diamond = levelConfig.diamondRewards; this.DiamondAwardLabel.string = "X" + StringUtils.numberUtilsEn(levelConfig.diamondRewards, 0); } else { this.diamond = 0; this.DiamondAwardLabel.string = ""; } } else {//失败 //失败不算奖励 this.WinGroup.active = false; this.DefeatedBackButton.active = false; this.scheduleOnce(() => { this.DefeatedBackButton.active = true; }, 2) this.DefeatedGroup.active = true; } // this.backButtonHandle(); } /** * 返回按钮误触 */ backButtonHandle(): void { // if (LiangLiangSDK.CanWuChu() == true) { // this.WinBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0); // this.DefeatedBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0); // this.scheduleOnce(() => { // PlatformManager.showBanner(); // this.WinBackButton.position = new Vec3(0, -375, 0); // this.DefeatedBackButton.position = new Vec3(0, -358, 0); // }, 3) // } else { // PlatformManager.showBanner(); // } } /** * 开始下一关 */ PlayNextLevel(): void { this.AddAward(); this.HideSelf(); GameController.single.PlayNextLevel(); } /** * 重玩 */ Replay(): void { PlatformManager.showRewardedVideo(() => { PlatformManager.hideBanner(); this.AddAward(); this.HideSelf(); GameController.single.Replay(); }, () => { NoticeManager.ShowPrompt("复活失败"); }) } /** * 返回主界面 */ BackToMain(): void { this.AddAward(); SceneManager.single.Swicth("PrepareScene"); GUIManager.single.Hide(UIConst.FIGHTING_UI); //关闭自身 this.HideSelf(); let qq = PlatformManager.impl as QQPlatform; if (qq instanceof QQPlatform) { qq.showInterstitialAd(); } } // /** // * 去全屏幕界面 // */ // GoToFullOutput(): void { // if (LiangLiangSDK.CanWuChu() == true) { // if (this.buttonCkilcBool == false) { // this.buttonCkilcBool = true; // this.scheduleOnce(() => { // PlatformManager.showBanner(); // this.scheduleOnce(() => { // PlatformManager.hideBanner(); // this.buttonClickIsOk = true; // }, 1) // }, 0.75) // } else { // if (this.buttonClickIsOk == true) { // this.buttonClickIsOk = false; // this.goOn(); // } // } // } else { // this.AddAward(); // // GUIManager.single.Show(UIConst.FULL_OUTPUT_UI); // this.HideSelf(); // SceneManager.single.Swicth("PrepareScene"); // } // } // goOn(): void { // let random: number = Math.random(); // if (random < 0.5) { // PlatformManager.showRewardedVideo(() => { // this.AddAward(); // this.HideSelf(); // }, () => { // this.AddAward(); // this.HideSelf(); // }) // } else { // this.AddAward(); // this.HideSelf(); // } // } /** * 十倍之后去全屏界面 */ getTenAward(): void { this.AddAdAward(10, () => { SceneManager.single.Swicth("PrepareScene"); this.HideSelf(); let qq = PlatformManager.impl as QQPlatform; if (qq instanceof QQPlatform) { qq.showInterstitialAd(); } }); } /** * 十倍奖励 * @param value */ private AddAdAward(value: number = 1, success): void { if (this.isWin) { PlatformManager.showRewardedVideo(() => { GameModel.single.gold += this.award * value; success(); }, () => { NoticeManager.ShowPrompt("领取失败"); }) } } /** * 获取奖励 */ private AddAward(value: number = 1): void { if (this.isWin) { GameModel.single.gold += this.award * value; GameModel.single.diamond += this.diamond * value; } } OnHide(): void { } }