FreeFenceMediator.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { _decorator, Component, Node, JsonAsset, SpriteComponent, LabelComponent, loader, SpriteFrame } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { DataModelEventType } from '../../../engines/models/DataModelEventType';
  5. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  6. import { SceneManager } from '../../../engines/scenes/SceneManager';
  7. import StringUtils from '../../../engines/utils/StringUtils';
  8. import { PlatformManager } from '../../../Platform/PlatformManager';
  9. import { branchIdType } from '../../../Platform/WeChat/branchIdType';
  10. import { WeChatPlatform } from '../../../Platform/WeChat/WeChatPlatform';
  11. import GameConfigManager from '../../models/GameConfigManager';
  12. import { GameModel } from '../../models/GameModel';
  13. import { GamePropertys } from '../../models/GamePropertys';
  14. import { GameController } from '../fightings/GameController';
  15. import { UIConst } from '../UIConst';
  16. const { ccclass, property } = _decorator;
  17. @ccclass('FreeFenceMediator')
  18. export class FreeFenceMediator extends GUIMediator {
  19. @property({
  20. type: LabelComponent
  21. })
  22. glodLabel: LabelComponent = null;
  23. @property({
  24. type: LabelComponent
  25. })
  26. glodLabel1: LabelComponent = null;
  27. @property({
  28. type: LabelComponent
  29. })
  30. diamondLabel: LabelComponent = null;
  31. private isFighting:boolean;
  32. OnShow(data?:any):void{
  33. super.OnShow(data);
  34. this.isFighting=data;
  35. this.AddEvent();
  36. this.RefreshGlod();
  37. this.RefreshDiamond();
  38. }
  39. OnHide():void{
  40. this.RemoveEvent();
  41. }
  42. private AddEvent():void{
  43. GameModel.single.AddEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged, 0);
  44. }
  45. private RemoveEvent():void{
  46. GameModel.single.RemoveEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged);
  47. }
  48. private GameModelPropertyChanged(key: string): void {
  49. switch (key) {
  50. case GamePropertys.gold:
  51. this.CallNextFrame(this.RefreshGlod.bind(this));
  52. break;
  53. case GamePropertys.diamond:
  54. this.CallNextFrame(this.RefreshDiamond.bind(this));
  55. break;
  56. }
  57. }
  58. private RefreshGlod(): void {
  59. if (this.glodLabel != null) {
  60. this.glodLabel.string = StringUtils.numberUtilsEn(GameModel.single.gold);
  61. }
  62. this.glodLabel1.string = StringUtils.numberUtilsEn(GameModel.single.fullEarnings) + "/秒";
  63. }
  64. private RefreshDiamond(): void {
  65. if (this.diamondLabel != null) {
  66. this.diamondLabel.string = GameModel.single.diamond.toString();
  67. }
  68. }
  69. /**
  70. * 视频按钮点击
  71. */
  72. VideoButtonClickHandler():void{
  73. PlatformManager.showRewardedVideo(()=>{
  74. GameModel.single.trialFenceId=30301;
  75. //看视频获得
  76. let weChat = PlatformManager.impl as WeChatPlatform;
  77. if(weChat instanceof WeChatPlatform){
  78. weChat.branchAnalytics(branchIdType.AdGet, String(GameModel.single.currentLevel))
  79. }
  80. if(this.isFighting){
  81. this.changeFence();
  82. }else{
  83. this.startGame();
  84. }
  85. },()=>{
  86. NoticeManager.ShowPrompt("看视频失败");
  87. });
  88. }
  89. CloseButtonClickHandler():void{
  90. if(this.isFighting){
  91. this.changeFence();
  92. }else{
  93. this.startGame();
  94. }
  95. }
  96. private startGame():void{
  97. //隐藏
  98. GUIManager.single.Hide(UIConst.PREPARE_UI);
  99. this.HideSelf();
  100. PlatformManager.hideBanner();
  101. SceneManager.single.Swicth("FightingScene");
  102. let weChat = PlatformManager.impl as WeChatPlatform
  103. if(weChat instanceof WeChatPlatform){
  104. // weChat.startBranchAnalytics(String(GameModel.single.currentLevel));
  105. weChat.branchAnalytics(branchIdType.EnterGame, String(GameModel.single.currentLevel))
  106. }
  107. }
  108. private changeFence():void{
  109. this.HideSelf();
  110. GameController.single.ChangeFence();
  111. GameController.single.PlayGame();
  112. }
  113. start () {
  114. // Your initialization goes here.
  115. }
  116. // update (deltaTime: number) {
  117. // // Your update function goes here.
  118. // }
  119. }