AutoSynthesisMediator.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, Node, 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 { DataModelEventType } from '../../../engines/models/DataModelEventType';
  7. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  8. import { PlatformManager } from '../../../Platform/PlatformManager';
  9. import AutoSyntheticBuffer from '../../buffers/AutoSyntheticBuffer';
  10. import GameConfigManager from '../../models/GameConfigManager';
  11. import { GameModel } from '../../models/GameModel';
  12. import { GamePropertys } from '../../models/GamePropertys';
  13. import { UIConst } from '../UIConst';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('AutoSynthesisMediator')
  16. export class AutoSynthesisMediator extends GUIMediator {
  17. @property({
  18. type:LabelComponent
  19. })
  20. diamondLabel:LabelComponent=null;
  21. private consume:number=20;
  22. private time:number=300*1000;
  23. start():void{
  24. this.consume=GameConfigManager.getGlobalValue("AutoSyntheticDiamondConsume");
  25. this.time=GameConfigManager.getGlobalValue("autoSyntheticTime")*1000;
  26. }
  27. OnShow(data?:any):void{
  28. super.OnShow(data);
  29. this.RefreshView();
  30. }
  31. OnHide():void{
  32. }
  33. private RefreshView():void{
  34. this.diamondLabel.string=this.consume.toString();
  35. }
  36. /**
  37. * 钻石按钮点击
  38. */
  39. DiamondButtonClickHandler():void{
  40. if(GameModel.single.diamond>this.consume){
  41. if(this.AddBuffer()){
  42. //扣钱
  43. GameModel.single.diamond-=this.consume;
  44. this.CloseButtonClickHandler();
  45. }
  46. }else{
  47. NoticeManager.ShowPrompt("钻石不足");
  48. }
  49. }
  50. /**
  51. * 视频按钮点击
  52. */
  53. VideoButtonClickHandler():void{
  54. PlatformManager.showRewardedVideo(()=>{
  55. this.AddBuffer();
  56. this.CloseButtonClickHandler();
  57. },()=>{
  58. NoticeManager.ShowPrompt("看视频失败");
  59. });
  60. }
  61. /**
  62. * 关闭按钮点击
  63. */
  64. CloseButtonClickHandler():void{
  65. GUIManager.single.Show(UIConst.PREPARE_UI);
  66. this.HideSelf();
  67. }
  68. private AddBuffer():boolean{
  69. let buffers:IBuffer[]=BufferManager.GetBufferGroup("AutoSynthesis");
  70. if(buffers!=null&&buffers.length>0){
  71. NoticeManager.ShowPrompt("自动合成已开启");
  72. return false;
  73. }
  74. let buffer:AutoSyntheticBuffer=new AutoSyntheticBuffer("AutoSynthesis",this.time);
  75. BufferManager.RunBuffer(buffer);
  76. return true;
  77. }
  78. }