AccelerateMediator.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { _decorator, Component, Node, ProgressBarComponent, LabelComponent } from 'cc';
  2. import BufferManager from '../../../engines/buffers/BufferManager';
  3. import IBuffer from '../../../engines/buffers/IBuffer';
  4. import { GUIManager } from '../../../engines/gui/GUIManager';
  5. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  6. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  7. import StringUtils from '../../../engines/utils/StringUtils';
  8. import { PlatformManager } from '../../../Platform/PlatformManager';
  9. import AccelerateBuffer from '../../buffers/AccelerateBuffer';
  10. import GameConfigManager from '../../models/GameConfigManager';
  11. import { GameModel } from '../../models/GameModel';
  12. import { UIConst } from '../UIConst';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('AccelerateMediator')
  15. export class AccelerateMediator extends GUIMediator {
  16. @property({
  17. type:ProgressBarComponent
  18. })
  19. progressBar:ProgressBarComponent=null;
  20. @property({
  21. type:LabelComponent
  22. })
  23. timeLabel:LabelComponent=null;
  24. @property({
  25. type:LabelComponent
  26. })
  27. diamondLabel:LabelComponent=null;
  28. /**
  29. * 最大时间
  30. */
  31. private max:number=150*1000*10;
  32. private time:number=150*1000;
  33. private consume:number=20;
  34. start():void{
  35. this.time=GameConfigManager.getGlobalValue("accelerateTime")*1000;
  36. this.max=GameConfigManager.getGlobalValue("accelerateMaxTime")*1000;
  37. this.consume=GameConfigManager.getGlobalValue("accelerateDiamondConsume");
  38. }
  39. OnShow(data?:any):void{
  40. super.OnShow(data);
  41. //消耗
  42. this.diamondLabel.string=this.consume.toString();
  43. }
  44. OnHide():void{
  45. }
  46. DiamondButtonClickHandler():void{
  47. if(GameModel.single.diamond>this.consume){
  48. if(this.CurrentBufferTime>=this.max){
  49. NoticeManager.ShowPrompt("加速时间已满!");
  50. return;
  51. }
  52. if(this.AddBuffer()){
  53. //扣钱
  54. GameModel.single.diamond-=this.consume;
  55. this.CloseButtonClickHandler();
  56. }
  57. }else{
  58. NoticeManager.ShowPrompt("钻石不足");
  59. }
  60. }
  61. /**
  62. * 视频按钮点击
  63. */
  64. VideoButtonClickHandler():void{
  65. if(this.CurrentBufferTime>=this.max){
  66. NoticeManager.ShowPrompt("加速时间已满!");
  67. return;
  68. }
  69. PlatformManager.showRewardedVideo(()=>{
  70. this.AddBuffer();
  71. },()=>{
  72. NoticeManager.ShowPrompt("看视频失败");
  73. });
  74. }
  75. /**
  76. * 关闭按钮点击
  77. */
  78. CloseButtonClickHandler():void{
  79. GUIManager.single.Show(UIConst.PREPARE_UI);
  80. this.HideSelf();
  81. }
  82. private AddBuffer():boolean{
  83. let buffer:AccelerateBuffer=new AccelerateBuffer("Accelerate",this.time);
  84. BufferManager.RunBuffer(buffer);
  85. return true;
  86. }
  87. private get CurrentBufferTime():number{
  88. let buffers:IBuffer[]=BufferManager.GetBufferGroup("Accelerate");
  89. if(buffers==null||buffers.length==0){
  90. return 0;
  91. }
  92. return buffers[0].GetTimeRemaining();
  93. }
  94. update(dt:number):void{
  95. this.progressBar.progress=this.CurrentBufferTime/this.max;
  96. this.timeLabel.string=StringUtils.TimeFormatting(this.CurrentBufferTime,":",":",":",":",":","");
  97. super.update(dt);
  98. }
  99. }