AutoSynthesisMediator.ts 2.4 KB

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