AutoSynthesisMediator.ts 3.1 KB

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