FreeFenceMediator.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 { UIConst } from '../UIConst';
  15. const { ccclass, property } = _decorator;
  16. @ccclass('FreeFenceMediator')
  17. export class FreeFenceMediator extends GUIMediator {
  18. @property({
  19. type: LabelComponent
  20. })
  21. glodLabel: LabelComponent = null;
  22. @property({
  23. type: LabelComponent
  24. })
  25. glodLabel1: LabelComponent = null;
  26. @property({
  27. type: LabelComponent
  28. })
  29. diamondLabel: LabelComponent = null;
  30. OnShow(data?:any):void{
  31. super.OnShow(data);
  32. this.AddEvent();
  33. this.RefreshGlod();
  34. this.RefreshDiamond();
  35. }
  36. OnHide():void{
  37. this.RemoveEvent();
  38. }
  39. private AddEvent():void{
  40. GameModel.single.AddEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged, 0);
  41. }
  42. private RemoveEvent():void{
  43. GameModel.single.RemoveEvent(DataModelEventType.PROPERTY_CHANGED, this, this.GameModelPropertyChanged);
  44. }
  45. private GameModelPropertyChanged(key: string): void {
  46. switch (key) {
  47. case GamePropertys.gold:
  48. this.CallNextFrame(this.RefreshGlod.bind(this));
  49. break;
  50. case GamePropertys.diamond:
  51. this.CallNextFrame(this.RefreshDiamond.bind(this));
  52. break;
  53. }
  54. }
  55. private RefreshGlod(): void {
  56. if (this.glodLabel != null) {
  57. this.glodLabel.string = StringUtils.numberUtilsEn(GameModel.single.gold);
  58. }
  59. this.glodLabel1.string = StringUtils.numberUtilsEn(GameModel.single.fullEarnings) + "/秒";
  60. }
  61. private RefreshDiamond(): void {
  62. if (this.diamondLabel != null) {
  63. this.diamondLabel.string = GameModel.single.diamond.toString();
  64. }
  65. }
  66. /**
  67. * 视频按钮点击
  68. */
  69. VideoButtonClickHandler():void{
  70. PlatformManager.showRewardedVideo(()=>{
  71. GameModel.single.trialFenceId=30301;
  72. //看视频获得
  73. let weChat = PlatformManager.impl as WeChatPlatform;
  74. if(weChat instanceof WeChatPlatform){
  75. weChat.branchAnalytics(branchIdType.AdGet, String(GameModel.single.currentLevel))
  76. }
  77. this.startGame();
  78. },()=>{
  79. NoticeManager.ShowPrompt("看视频失败");
  80. });
  81. }
  82. CloseButtonClickHandler():void{
  83. this.startGame();
  84. }
  85. private startGame():void{
  86. //隐藏
  87. GUIManager.single.Hide(UIConst.PREPARE_UI);
  88. this.HideSelf();
  89. PlatformManager.hideBanner();
  90. SceneManager.single.Swicth("FightingScene");
  91. let weChat = PlatformManager.impl as WeChatPlatform
  92. if(weChat instanceof WeChatPlatform){
  93. // weChat.startBranchAnalytics(String(GameModel.single.currentLevel));
  94. weChat.branchAnalytics(branchIdType.EnterGame, String(GameModel.single.currentLevel))
  95. }
  96. }
  97. start () {
  98. // Your initialization goes here.
  99. }
  100. // update (deltaTime: number) {
  101. // // Your update function goes here.
  102. // }
  103. }