AutoSynthesisMediator.ts 3.3 KB

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