GameOverMediator.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { _decorator, Component, Node, LabelComponent, Vec2, Vec3, view } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  5. import { SceneManager } from '../../../engines/scenes/SceneManager';
  6. import StringUtils from '../../../engines/utils/StringUtils';
  7. import { LiangLiangSDK } from '../../../libs/liangliangSDK';
  8. import { PlatformManager } from '../../../Platform/PlatformManager';
  9. import { QQPlatform } from '../../../Platform/QQ/QQPlatform';
  10. import { branchIdType } from '../../../Platform/WeChat/branchIdType';
  11. import { WeChatPlatforms } from '../../../Platform/WeChat/WeChatPlatforms';
  12. import GameConfigManager from '../../models/GameConfigManager';
  13. import { GameModel } from '../../models/GameModel';
  14. import { GameController } from '../fightings/GameController';
  15. import { UIConst } from '../UIConst';
  16. const { ccclass, property } = _decorator;
  17. @ccclass('GameOverMediator')
  18. export class GameOverMediator extends GUIMediator {
  19. @property(Node)
  20. WinGroup: Node = null;
  21. @property({
  22. type: Node
  23. })
  24. WinAwardNode: Node = null;
  25. @property({
  26. type: LabelComponent
  27. })
  28. WinAwardLabel: LabelComponent = null;
  29. @property({
  30. type: Node
  31. })
  32. DiamondAwardNode: Node = null;
  33. @property({
  34. type: LabelComponent
  35. })
  36. DiamondAwardLabel: LabelComponent = null;
  37. @property(Node)
  38. DefeatedGroup: Node = null;
  39. @property(Node)
  40. WinBackButton: Node = null;
  41. @property(Node)
  42. DefeatedBackButton: Node = null;
  43. private isWin: boolean;
  44. private award: number;
  45. private diamond: number;
  46. private buttonCkilcBool: boolean = false;
  47. private buttonClickIsOk: boolean = false;
  48. onLoad() {
  49. // PlatformManager.showBanner()
  50. }
  51. OnShow(data?: any): void {
  52. super.OnShow(data);
  53. this.isWin = data;
  54. this.WinGroup.active = this.isWin;
  55. this.DefeatedGroup.active = !this.isWin;
  56. this.buttonCkilcBool = false;
  57. this.buttonClickIsOk = false;
  58. PlatformManager.showBanner();
  59. //胜利
  60. if (this.isWin == true) {
  61. this.WinBackButton.active = false;
  62. this.scheduleOnce(() => {
  63. this.WinBackButton.active = true;
  64. }, 2);
  65. this.WinGroup.active = true;
  66. this.DefeatedGroup.active = false;
  67. let levelConfig: any = GameConfigManager.GetLevelConfig(GameModel.single.currentLevel - 1);
  68. //关卡基础奖励
  69. this.award = levelConfig.awards + levelConfig.killAward * GameModel.single.killCount;
  70. //金币奖励
  71. this.WinAwardLabel.string = "X" + StringUtils.numberUtilsEn(this.award, 0);
  72. //钻石奖励
  73. if (levelConfig.diamondRewards > 0) {
  74. this.diamond = levelConfig.diamondRewards;
  75. this.DiamondAwardLabel.string = "X" + StringUtils.numberUtilsEn(levelConfig.diamondRewards, 0);
  76. } else {
  77. this.diamond = 0;
  78. this.DiamondAwardLabel.string = "";
  79. }
  80. } else {//失败
  81. //失败不算奖励
  82. this.WinGroup.active = false;
  83. this.DefeatedBackButton.active = false;
  84. this.scheduleOnce(() => {
  85. this.DefeatedBackButton.active = true;
  86. }, 2)
  87. this.DefeatedGroup.active = true;
  88. }
  89. // this.backButtonHandle();
  90. }
  91. /**
  92. * 返回按钮误触
  93. */
  94. backButtonHandle(): void {
  95. // if (LiangLiangSDK.CanWuChu() == true) {
  96. // this.WinBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0);
  97. // this.DefeatedBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0);
  98. // this.scheduleOnce(() => {
  99. // PlatformManager.showBanner();
  100. // this.WinBackButton.position = new Vec3(0, -375, 0);
  101. // this.DefeatedBackButton.position = new Vec3(0, -358, 0);
  102. // }, 3)
  103. // } else {
  104. // PlatformManager.showBanner();
  105. // }
  106. }
  107. /**
  108. * 开始下一关
  109. */
  110. PlayNextLevel(): void {
  111. this.AddAward();
  112. this.HideSelf();
  113. GameController.single.PlayNextLevel();
  114. }
  115. /**
  116. * 重玩
  117. */
  118. Replay(): void {
  119. PlatformManager.showRewardedVideo(() => {
  120. PlatformManager.hideBanner();
  121. this.AddAward();
  122. this.HideSelf();
  123. GameController.single.Replay();
  124. }, () => {
  125. NoticeManager.ShowPrompt("复活失败");
  126. })
  127. }
  128. /**
  129. * 返回主界面
  130. */
  131. BackToMain(): void {
  132. this.AddAward();
  133. SceneManager.single.Swicth("PrepareScene");
  134. GUIManager.single.Hide(UIConst.FIGHTING_UI);
  135. //关闭自身
  136. this.HideSelf();
  137. let qq = PlatformManager.impl as QQPlatform;
  138. if (qq instanceof QQPlatform) {
  139. qq.showInterstitialAd();
  140. }
  141. }
  142. // /**
  143. // * 去全屏幕界面
  144. // */
  145. // GoToFullOutput(): void {
  146. // if (LiangLiangSDK.CanWuChu() == true) {
  147. // if (this.buttonCkilcBool == false) {
  148. // this.buttonCkilcBool = true;
  149. // this.scheduleOnce(() => {
  150. // PlatformManager.showBanner();
  151. // this.scheduleOnce(() => {
  152. // PlatformManager.hideBanner();
  153. // this.buttonClickIsOk = true;
  154. // }, 1)
  155. // }, 0.75)
  156. // } else {
  157. // if (this.buttonClickIsOk == true) {
  158. // this.buttonClickIsOk = false;
  159. // this.goOn();
  160. // }
  161. // }
  162. // } else {
  163. // this.AddAward();
  164. // // GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  165. // this.HideSelf();
  166. // SceneManager.single.Swicth("PrepareScene");
  167. // }
  168. // }
  169. // goOn(): void {
  170. // let random: number = Math.random();
  171. // if (random < 0.5) {
  172. // PlatformManager.showRewardedVideo(() => {
  173. // this.AddAward();
  174. // this.HideSelf();
  175. // }, () => {
  176. // this.AddAward();
  177. // this.HideSelf();
  178. // })
  179. // } else {
  180. // this.AddAward();
  181. // this.HideSelf();
  182. // }
  183. // }
  184. /**
  185. * 十倍之后去全屏界面
  186. */
  187. getTenAward(): void {
  188. this.AddAdAward(10, () => {
  189. SceneManager.single.Swicth("PrepareScene");
  190. this.HideSelf();
  191. let qq = PlatformManager.impl as QQPlatform;
  192. if (qq instanceof QQPlatform) {
  193. qq.showInterstitialAd();
  194. }
  195. });
  196. }
  197. /**
  198. * 十倍奖励
  199. * @param value
  200. */
  201. private AddAdAward(value: number = 1, success): void {
  202. if (this.isWin) {
  203. PlatformManager.showRewardedVideo(() => {
  204. GameModel.single.gold += this.award * value;
  205. success();
  206. }, () => {
  207. NoticeManager.ShowPrompt("领取失败");
  208. })
  209. }
  210. }
  211. /**
  212. * 获取奖励
  213. */
  214. private AddAward(value: number = 1): void {
  215. if (this.isWin) {
  216. GameModel.single.gold += this.award * value;
  217. GameModel.single.diamond += this.diamond * value;
  218. }
  219. }
  220. OnHide(): void {
  221. }
  222. }