123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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 { branchIdType } from '../../../Platform/WeChat/branchIdType';
- import { WeChatPlatform } from '../../../Platform/WeChat/WeChatPlatform';
- 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;
- //胜利
- 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 = "";
- }
- let weChat = PlatformManager.impl as WeChatPlatform;
- if (weChat instanceof WeChatPlatform) {
- // weChat.successBranchAnalytics(String(GameModel.single.currentLevel));
- weChat.branchAnalytics(branchIdType.SuccessGame, String(GameModel.single.currentLevel))
- }
- } else {//失败
- //失败不算奖励
- this.WinGroup.active = false;
- this.DefeatedBackButton.active = false;
- this.scheduleOnce(()=>{
- this.DefeatedBackButton.active = true;
- }, 2)
- this.DefeatedGroup.active = true;
- let weChat = PlatformManager.impl as WeChatPlatform;
- if (weChat instanceof WeChatPlatform) {
- // weChat.failBranchAnalytics(String(GameModel.single.currentLevel));
- weChat.branchAnalytics(branchIdType.FailGame, String(GameModel.single.currentLevel))
- }
- }
- // 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();
- }
- /**
- * 去全屏幕界面
- */
- 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)
- }, 1)
- }else{
- if(this.buttonClickIsOk == true){
- this.buttonClickIsOk = false;
- this.goOn();
- }
- }
- }else{
- this.AddAward();
- GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
- this.HideSelf();
- }
- }
- goOn():void{
- let random:number = Math.random();
- if(random < 0.5){
- PlatformManager.showRewardedVideo(()=>{
- this.AddAward();
- GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
- this.HideSelf();
- }, ()=>{
- this.AddAward();
- GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
- this.HideSelf();
- })
- }else{
- this.AddAward();
- GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
- this.HideSelf();
- }
- }
- /**
- * 十倍之后去全屏界面
- */
- getTenAward(): void {
- this.AddAdAward(10, () => {
- GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
- this.HideSelf();
- });
- }
- /**
- * 十倍奖励
- * @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 {
- }
- }
|