hallScene.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { BaseView } from "../lightMVC/core/base/BaseView";
  2. import SDK from "./sdk/SDK";
  3. import hallSceneMediator from "./hallSceneMediator";
  4. import { App } from "./Manager/App";
  5. import { SoundManager } from "./Manager/SoundManager";
  6. import TimeControl from "./TimeControl";
  7. import ChooseLevelPanel from "./view/chooseLevel/ChooseLevelPanel";
  8. import ChooseLevelPanelMediator from "./view/chooseLevel/ChooseLevelPanelMediator";
  9. import ChooseSkinPanel from "./view/chooseSkin/ChooseSkinPanel";
  10. import ChooseSkinPanelMediator from "./view/chooseSkin/ChooseSkinPanelMediator";
  11. import InsufficientPanel from "./view/insufficientPanel/InsufficientPanel";
  12. import InsufficientPanelMediator from "./view/insufficientPanel/InsufficientPanelMediator";
  13. import MissionPanel from "./view/missionPanel/MissionPanel";
  14. import MissionPanelMediator from "./view/missionPanel/MissionPanelMediator";
  15. import SetNormalPanel from "./view/setNormal/SetNormalPanel";
  16. import SetNormalPanelMediator from "./view/setNormal/SetNormalPanelMediator";
  17. import ShopPanel from "./view/shopView/ShopPanel";
  18. import ShopPanelMediator from "./view/shopView/ShopPanelMediator";
  19. import TipPanel from "./view/tipPanel/TipPanel";
  20. import TipPanelMediator from "./view/tipPanel/TipPanelMediator";
  21. const { ccclass, property } = cc._decorator;
  22. @ccclass
  23. export default class hallScene extends BaseView {
  24. public static _instance;
  25. @property(cc.Button)
  26. public startGameBtn: cc.Button = null;
  27. @property(cc.Button)
  28. public setNormalBtn: cc.Button = null;
  29. // @property(cc.Button)
  30. // public chooseSkinBtn: cc.Button = null;
  31. @property(cc.Button)
  32. public missionBtn: cc.Button = null;
  33. // @property(cc.Button)
  34. // public btnVideo: cc.Button = null;
  35. // @property(cc.Button)
  36. // public btnShop: cc.Button = null;
  37. @property(cc.Button)
  38. public btnLeft: cc.Button = null;
  39. @property(cc.Button)
  40. public btnRight: cc.Button = null;
  41. @property(cc.PageView)
  42. public pageView: cc.PageView = null;
  43. @property(cc.Label)
  44. public labelTili: cc.Label = null;
  45. @property(cc.Label)
  46. public physicalTime: cc.Label = null;
  47. @property(cc.Label)
  48. public labelCoin: cc.Label = null;
  49. @property(cc.Label)
  50. public labelDiamond: cc.Label = null;
  51. private loadSceneName: string = "gameScene";
  52. private currientView = 0;
  53. public static get instance() {
  54. return hallScene._instance;
  55. }
  56. public static set instance(value) {
  57. hallScene._instance = value;
  58. }
  59. onLoad() {
  60. // cc.sys.localStorage.clear();
  61. hallScene.instance = this;
  62. this.registerMediator(hallSceneMediator, this, "主界面");
  63. SDK.Instance.showBanner();
  64. }
  65. start() {
  66. this.startGameBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this);
  67. this.setNormalBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this);
  68. this.btnLeft.node.on(cc.Node.EventType.TOUCH_END, this.ClickLeft, this);
  69. this.btnRight.node.on(cc.Node.EventType.TOUCH_END, this.ClickRight, this);
  70. // this.btnVideo.node.on(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this);
  71. this.missionBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this);
  72. // this.chooseSkinBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this);
  73. // this.btnShop.node.on(cc.Node.EventType.TOUCH_END, this.ClickShop, this);
  74. // console.log('----------', TimeControl.instance.currentTili);
  75. // App.DataManager.TimeCountJudge();//全局倒计时判断
  76. // if (App.DataManager.TimeFlag) {
  77. // let data = { "isShow": true, 'timeStr': App.DataManager.TimeChange(TimeControl.instance.currentTimeCount) };
  78. // this.TiliCountShow(data);
  79. // }
  80. this.ShowPhysicalValue();
  81. this.ShowUserCoinValue();
  82. this.ShowUserDiamondValue();
  83. App.SoundManager.playBGM(SoundManager.hallBgm[0]);
  84. }
  85. public ClickOpenMission() {
  86. App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false);
  87. }
  88. /**
  89. * 体力显示设置
  90. */
  91. public ShowPhysicalValue(): void {
  92. console.log('############', TimeControl.instance.currentTili)
  93. if(hallScene.instance.labelTili){
  94. hallScene.instance.labelTili.string = TimeControl.instance.currentTili + "/" + TimeControl.instance.tiliMax;
  95. }
  96. }
  97. // 显示玩家金币
  98. public ShowUserCoinValue(): void {
  99. if(hallScene.instance.labelCoin){
  100. hallScene.instance.labelCoin.string = App.DataManager.UserCoin.toString();
  101. }
  102. }
  103. // 钻石
  104. public ShowUserDiamondValue(): void {
  105. if(hallScene.instance.labelDiamond){
  106. hallScene.instance.labelDiamond.string = App.DataManager.UserDiamond.toString();
  107. }
  108. }
  109. /**
  110. * 体力倒计时显示设置
  111. */
  112. public TiliCountShow(data: any): void {
  113. if (!this.physicalTime) return;
  114. this.physicalTime.node.active = data.isShow;
  115. if (data.timeStr) this.physicalTime.string = data.timeStr;
  116. }
  117. /**
  118. * 开始游戏
  119. */
  120. public StartGame(intoLevel: number) {
  121. console.log("aaa--------intoLevel----------", intoLevel);
  122. App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => {
  123. App.DataManager.CurrentIntoLevel = intoLevel;
  124. App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel;
  125. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, App.DataManager.PlayLevel);
  126. if (success) App.Facade.runBundleScene("gameScene",this.loadSceneName);
  127. else App.Facade.popView(InsufficientPanelMediator, InsufficientPanel, "体力不足", false);
  128. });
  129. }
  130. /**
  131. * 点击开始游戏按钮直接开始
  132. */
  133. private ClickStartGame() {
  134. if(this.pageView.getCurrentPageIndex() == 1){
  135. App.Facade.popView(TipPanelMediator, TipPanel, "敬请期待!", false);
  136. }
  137. else{
  138. App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", false);
  139. }
  140. }
  141. /**
  142. * 点击观看视频加体力
  143. */
  144. private ClickAddTili() {
  145. console.log('点击观看视频加体力~');
  146. SoundManager.getInstance().VideoStartStop();
  147. SDK.Instance.showRewardVideo(() => {
  148. TimeControl.instance.currentTili = TimeControl.instance.tiliMax;
  149. this.ShowPhysicalValue();
  150. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili);
  151. SoundManager.getInstance().VideoEndOpen();
  152. }, () => {
  153. SoundManager.getInstance().VideoEndOpen();
  154. }, () => {
  155. SoundManager.getInstance().VideoEndOpen();
  156. });
  157. }
  158. // 商城
  159. private ClickShop() {
  160. App.Facade.popView(ShopPanelMediator, ShopPanel, "商城", false);
  161. }
  162. /**
  163. * 打开关卡选择界面
  164. */
  165. private ClickChooseLevel() {
  166. App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", true);
  167. }
  168. /**
  169. * 打开选择皮肤界面
  170. */
  171. private ClickChooseSkin() {
  172. App.Facade.popView(ChooseSkinPanelMediator, ChooseSkinPanel, "皮肤选择", false);
  173. }
  174. /**
  175. * 打开设置界面
  176. */
  177. private ClickSetNormal() {
  178. App.Facade.popView(SetNormalPanelMediator, SetNormalPanel, "设置", false);
  179. }
  180. private ClickLeft(){
  181. this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0;
  182. this.pageView.scrollToPage(this.currientView, 0.5);
  183. }
  184. private ClickRight(){
  185. this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0;
  186. this.pageView.scrollToPage(this.currientView, 0.5);
  187. }
  188. onDisable() {
  189. this.startGameBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this);
  190. this.setNormalBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this);
  191. this.btnLeft.node.off(cc.Node.EventType.TOUCH_END, this.ClickLeft, this);
  192. this.btnRight.node.off(cc.Node.EventType.TOUCH_END, this.ClickRight, this);
  193. this.missionBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this);
  194. // this.btnVideo.node.off(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this);
  195. // this.btnShop.node.off(cc.Node.EventType.TOUCH_END, this.ClickShop, this);
  196. // this.chooseSkinBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this);
  197. }
  198. // update (dt) {}
  199. }