123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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 { 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;
- /**
- * 最大时间
- */
- private max:number=150*1000*10;
- OnShow(data?:any):void{
- super.OnShow(data);
- }
- OnHide():void{
-
- }
- DiamondButtonClickHandler():void{
- if(GameModel.single.diamond>20){
- if(this.CurrentBufferTime>=this.max){
- NoticeManager.ShowPrompt("加速时间已满!");
- return;
- }
- if(this.AddBuffer()){
- //扣钱
- GameModel.single.diamond-=20;
- 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",150*1000);
- 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].GetTime();
- }
- update(dt:number):void{
- this.progressBar.progress=this.CurrentBufferTime/this.max;
- this.timeLabel.string=StringUtils.TimeFormatting(this.CurrentBufferTime,":",":",":","");
- super.update(dt);
- }
- }
|