import { _decorator, Component, Node, ProgressBarComponent, LabelComponent } from 'cc'; import BufferManager from '../../../engines/buffers/BufferManager'; import IBuffer from '../../../engines/buffers/IBuffer'; import { GUIManager } from '../../../engines/gui/GUIManager'; import { GUIMediator } from '../../../engines/gui/GUIMediator'; import { NoticeManager } from '../../../engines/notices/NoticeManager'; import StringUtils from '../../../engines/utils/StringUtils'; import { PlatformManager } from '../../../Platform/PlatformManager'; import AccelerateBuffer from '../../buffers/AccelerateBuffer'; import GameConfigManager from '../../models/GameConfigManager'; import { GameModel } from '../../models/GameModel'; import { UIConst } from '../UIConst'; const { ccclass, property } = _decorator; @ccclass('AccelerateMediator') export class AccelerateMediator extends GUIMediator { @property({ type:ProgressBarComponent }) progressBar:ProgressBarComponent=null; @property({ type:LabelComponent }) timeLabel:LabelComponent=null; @property({ type:LabelComponent }) diamondLabel:LabelComponent=null; /** * 最大时间 */ private max:number=150*1000*10; private time:number=150*1000; private consume:number=20; start():void{ this.time=GameConfigManager.getGlobalValue("accelerateTime")*1000; this.max=GameConfigManager.getGlobalValue("accelerateMaxTime")*1000; this.consume=GameConfigManager.getGlobalValue("accelerateDiamondConsume"); } OnShow(data?:any):void{ super.OnShow(data); //消耗 this.diamondLabel.string=this.consume.toString(); } OnHide():void{ } DiamondButtonClickHandler():void{ if(GameModel.single.diamond>this.consume){ if(this.CurrentBufferTime>=this.max){ NoticeManager.ShowPrompt("加速时间已满!"); return; } if(this.AddBuffer()){ //扣钱 GameModel.single.diamond-=this.consume; this.CloseButtonClickHandler(); } }else{ NoticeManager.ShowPrompt("钻石不足"); } } /** * 视频按钮点击 */ VideoButtonClickHandler():void{ if(this.CurrentBufferTime>=this.max){ NoticeManager.ShowPrompt("加速时间已满!"); return; } PlatformManager.showRewardedVideo(()=>{ this.AddBuffer(); },()=>{ NoticeManager.ShowPrompt("看视频失败"); }); } /** * 关闭按钮点击 */ CloseButtonClickHandler():void{ GUIManager.single.Show(UIConst.PREPARE_UI); this.HideSelf(); } private AddBuffer():boolean{ let buffer:AccelerateBuffer=new AccelerateBuffer("Accelerate",this.time); BufferManager.RunBuffer(buffer); return true; } private get CurrentBufferTime():number{ let buffers:IBuffer[]=BufferManager.GetBufferGroup("Accelerate"); if(buffers==null||buffers.length==0){ return 0; } return buffers[0].GetTimeRemaining(); } update(dt:number):void{ this.progressBar.progress=this.CurrentBufferTime/this.max; this.timeLabel.string=StringUtils.TimeFormatting(this.CurrentBufferTime,":",":",":",":",":",""); super.update(dt); } }