123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import { _decorator, Component, Node, JsonAsset, SpriteComponent, LabelComponent, loader, SpriteFrame } from 'cc';
- import { GUIManager } from '../../../engines/gui/GUIManager';
- import { GUIMediator } from '../../../engines/gui/GUIMediator';
- import { DataModelEventType } from '../../../engines/models/DataModelEventType';
- import { NoticeManager } from '../../../engines/notices/NoticeManager';
- import { SceneManager } from '../../../engines/scenes/SceneManager';
- import StringUtils from '../../../engines/utils/StringUtils';
- 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 { GamePropertys } from '../../models/GamePropertys';
- import { GameController } from '../fightings/GameController';
- import { UIConst } from '../UIConst';
- const { ccclass, property } = _decorator;
- @ccclass('FreeFenceMediator')
- export class FreeFenceMediator extends GUIMediator {
- @property({
- type: LabelComponent
- })
- glodLabel: LabelComponent = null;
- @property({
- type: LabelComponent
- })
- glodLabel1: LabelComponent = null;
- @property({
- type: LabelComponent
- })
- diamondLabel: LabelComponent = null;
- private isFighting:boolean;
- OnShow(data?:any):void{
- super.OnShow(data);
- this.isFighting=data;
- this.AddEvent();
- this.RefreshGlod();
- this.RefreshDiamond();
- }
- OnHide():void{
- this.RemoveEvent();
- }
- private AddEvent():void{
- GameModel.single.AddEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged, 0);
- }
- private RemoveEvent():void{
- GameModel.single.RemoveEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged);
- }
- private GameModelPropertyChanged(key: string): void {
- switch (key) {
- case GamePropertys.gold:
- this.CallNextFrame(this.RefreshGlod.bind(this));
- break;
- case GamePropertys.diamond:
- this.CallNextFrame(this.RefreshDiamond.bind(this));
- break;
- }
- }
- private RefreshGlod(): void {
- if (this.glodLabel != null) {
- this.glodLabel.string = StringUtils.numberUtilsEn(GameModel.single.gold);
- }
- this.glodLabel1.string = StringUtils.numberUtilsEn(GameModel.single.fullEarnings) + "/秒";
- }
- private RefreshDiamond(): void {
- if (this.diamondLabel != null) {
- this.diamondLabel.string = GameModel.single.diamond.toString();
- }
- }
- /**
- * 视频按钮点击
- */
- VideoButtonClickHandler():void{
- PlatformManager.showRewardedVideo(()=>{
- GameModel.single.trialFenceId=30301;
- //看视频获得
- let weChat = PlatformManager.impl as WeChatPlatform;
- if(weChat instanceof WeChatPlatform){
- weChat.branchAnalytics(branchIdType.AdGet, String(GameModel.single.currentLevel))
- }
- if(this.isFighting){
- this.changeFence();
- }else{
- this.startGame();
- }
- },()=>{
- NoticeManager.ShowPrompt("看视频失败");
- });
- }
- CloseButtonClickHandler():void{
- if(this.isFighting){
- this.changeFence();
- }else{
- this.startGame();
- }
- }
- private startGame():void{
- //隐藏
- GUIManager.single.Hide(UIConst.PREPARE_UI);
- this.HideSelf();
- PlatformManager.hideBanner();
- SceneManager.single.Swicth("FightingScene");
- let weChat = PlatformManager.impl as WeChatPlatform
- if(weChat instanceof WeChatPlatform){
- // weChat.startBranchAnalytics(String(GameModel.single.currentLevel));
- weChat.branchAnalytics(branchIdType.EnterGame, String(GameModel.single.currentLevel))
- }
- }
- private changeFence():void{
- this.HideSelf();
- GameController.single.ChangeFence();
- GameController.single.PlayGame();
- }
- start () {
- // Your initialization goes here.
- }
- // update (deltaTime: number) {
- // // Your update function goes here.
- // }
- }
|