Start.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import PlayerConst from "./data/PlayerConst";
  2. import GameConst from "./data/GameConst";
  3. import Util from "./util/Util";
  4. import SelectSceneItem from "./view/uiItem/SelectSceneItem";
  5. import GameMgr, { UI_NAME } from "./mgr/GameMgr";
  6. import { EVENT_TYPE } from "../game/data/GameData";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class Start extends cc.Component {
  10. public static Inst: Start = null;
  11. @property(cc.Node)
  12. node_bg: cc.Node = null;
  13. @property(cc.Node)
  14. node_top: cc.Node = null;
  15. @property(cc.Node)
  16. node_scene: cc.Node = null;
  17. @property(cc.Node)
  18. node_leftBtn: cc.Node = null;
  19. @property(cc.Node)
  20. node_rightBtn: cc.Node = null;
  21. @property(cc.Node)
  22. node_startGameBtn: cc.Node = null;
  23. // LIFE-CYCLE CALLBACKS:
  24. onLoad() {
  25. Start.Inst = this;
  26. // HttpMgr.Inst.shopGoodsList();
  27. // HttpMgr.Inst.shopPrizeList();
  28. }
  29. start() {
  30. mk.console.log(" if(cc.sys.isBrowser)", cc.sys.isBrowser);
  31. this.adapt();
  32. this.initView();
  33. this.initEvent();
  34. }
  35. /**适配*/
  36. adapt() {
  37. this.node_bg.width = cc.winSize.width;
  38. this.node_bg.height = cc.winSize.height;
  39. let gap = ((cc.winSize.height - 100) - 1344) * 0.5
  40. this.node_top.y += gap;
  41. }
  42. onEnable() {
  43. // if (Game.Inst && Game.Inst.node.active) {
  44. // Game.Inst.restart();
  45. // }
  46. GameMgr.Inst.sendEvent(UI_NAME.Start, "进入主界面");
  47. //this.adapt();
  48. //AudioMgr.Inst.playMusic(AUDIO_CLIP_NAME.bg_start);
  49. mk.audio.playMusic("music_startBg");
  50. }
  51. onDisable() {
  52. }
  53. initView() {
  54. //this.adapt();
  55. this.initHead();
  56. this.initNickName();
  57. this.initCashNum();
  58. this.initEnergyNum();
  59. this.initShopScoreNum();
  60. this.initEnergyRecoverTime();
  61. this.initSelectSceneItem();
  62. }
  63. /** */
  64. initPlayerInfo() {
  65. }
  66. /**初始化头像 */
  67. initHead() {
  68. mk.console.log("开始界面初始化 Head111111111111111111", PlayerConst.headImgUrl);
  69. //LoaderUtil.loadHeadImg(this.spr_playerHead, 100);
  70. }
  71. initNickName() {
  72. mk.console.log("开始界面初始化 NickName111111111111111111", PlayerConst.nickName);
  73. //this.label_nickName.string = PlayerConst.nickName.toString();
  74. }
  75. initCashNum() {
  76. //Start界面需要先隐藏
  77. // LogUtil.log("PlayerConst.cashNum!!!!!!!!!!!!!!!!",PlayerConst.cashNum);
  78. // let num = Math.round((PlayerConst.cashNum * 100)) / 100;
  79. let num = Util.numberFixed(PlayerConst.cashNum, 2);
  80. //this.label_cashNum.string = `¥ ${num}`;
  81. }
  82. /**初始化能量值 */
  83. initEnergyNum() {
  84. // //如果体力无值
  85. // if (!PlayerConst.energyNum) {
  86. // PlayerConst.energyNum = 0;
  87. // }
  88. // if (PlayerConst.energyNum >= GameConst.maxEnergyNum) {
  89. // this.label_energyNum.string = "10(满)";
  90. // this.label_energyRecoverTime.node.active = false;
  91. // }
  92. // else {
  93. // this.label_energyNum.string = PlayerConst.energyNum.toString();
  94. // }
  95. // if (PlayerConst.energyNum < GameConst.maxEnergyNum) {
  96. // if (!PlayerConst.leftEnergyRecoverTime) {
  97. // PlayerConst.leftEnergyRecoverTime = GameConst.recoverTimePerEnergy;
  98. // }
  99. // DataMgr.Inst.recoverEnergyNum();
  100. // this.initEnergyRecoverTime();
  101. // }
  102. }
  103. initEnergyRecoverTime() {
  104. // this.label_energyRecoverTime.string = Util.ParseTime2Format(PlayerConst.leftEnergyRecoverTime, "m:s");
  105. }
  106. initShopScoreNum() {
  107. // this.label_shopScoreNum.string = PlayerConst.shopScoreNum.toString();
  108. }
  109. initSelectSceneItem() {
  110. mk.loader.load("prefab/SelectSceneItem", cc.Prefab).then((prefab) => {
  111. for (var i = 0; i <= GameConst.maxIconIndex; i++) {
  112. let node_selectSceneItem: cc.Node = cc.instantiate(prefab);
  113. if (i < GameConst.maxIconIndex) {
  114. node_selectSceneItem.getComponent(SelectSceneItem).init(i);
  115. }
  116. else {
  117. node_selectSceneItem.getComponent(SelectSceneItem).init();
  118. }
  119. this.node_scene.addChild(node_selectSceneItem);
  120. }
  121. this.node_scene.getComponent(cc.Layout).updateLayout;
  122. this.setNodeSelectScenePos(GameConst.iconIndex);
  123. }).catch(() => {
  124. })
  125. }
  126. /**初始化事件 */
  127. initEvent() {
  128. this.node_startGameBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  129. this.node_leftBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  130. this.node_rightBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  131. if (!GameConst.isAuth) {
  132. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  133. }
  134. }
  135. // update (dt) {}
  136. onClick(event: cc.Event.EventTouch) {
  137. //EffectMgr.Inst.addTip("点击按钮!!!!!!!!!!!!!!!")
  138. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  139. mk.audio.playEffect("ef_button_click");
  140. // switch (event.currentTarget) {
  141. // case this.node_playerInfo:
  142. // this.onClickPlayerInfo();
  143. // break;
  144. // case this.node_energy:
  145. // this.onClickEnergy();
  146. // break;
  147. // case this.node_settingBtn:
  148. // this.onClickSettingBtn();
  149. // break;
  150. // case this.node_clockInBtn:
  151. // this.onClickClockInBtn();
  152. // break;
  153. // case this.node_startGameBtn:
  154. // this.onClickStartGameBtn();
  155. // break;
  156. // case this.node_leftBtn:
  157. // this.onClickLeftBtn();
  158. // break;
  159. // case this.node_rightBtn:
  160. // this.onClickRightBtn();
  161. // break;
  162. // case this.node_cashOutBtn:
  163. // this.onClickCashOutBtn();
  164. // break;
  165. // case this.node_dailyCashOutBtn:
  166. // this.onClickDailyCashOutBtn();
  167. // break;
  168. // case this.node_shopScore:
  169. // this.onClickShopScore();
  170. // break;
  171. // case this.node_shopBtn:
  172. // this.onClickShopBtn();
  173. // break;
  174. // case this.node_shopActivityBtn:
  175. // this.onClickShopActivityBtn();
  176. // break;
  177. // case this.node_moreGameBtn:
  178. // this.onClickMoreGameBtn();
  179. // break;
  180. // case this.node_turnplateBtn:
  181. // this.onClickTurnplateBtn();
  182. // break;
  183. // case this.node_shareBtn:
  184. // this.onClickShareBtn();
  185. // break;
  186. // case this.node_bankBtn:
  187. // this.onClickBankBtn();
  188. // break;
  189. // case this.node_luckPacketBtn:
  190. // this.onClickLuckyPacketBtn();
  191. // break;
  192. // case this.node_signBtn:
  193. // this.onClickSignBtn();
  194. // break;
  195. // }
  196. }
  197. onClickPlayerInfo() {
  198. GameMgr.Inst.sendEvent(UI_NAME.Start, "点击玩家信息按钮");
  199. mk.ui.openPanel("PlayerInfoUI");
  200. //JsbMgr.ShareToMiniGame();
  201. }
  202. onClickSettingBtn() {
  203. GameMgr.Inst.sendEvent(UI_NAME.Start, "点击设置按钮");
  204. mk.ui.openPanel("SettingUI");
  205. }
  206. onClickStartGameBtn() {
  207. GameMgr.Inst.sendEvent(UI_NAME.Start, "点击开始按钮");
  208. if (PlayerConst.energyNum <= 0) {
  209. mk.ui.openPanel("GetEnergyUI");
  210. return;
  211. }
  212. // if (GameConst.iconIndex >= GameConst.maxIconIndex) {
  213. // EffectMgr.Inst.addTip("场景未解锁,请选择解锁场景");
  214. // return;
  215. // }
  216. if (GameConst.iconIndex >= GameConst.maxIconIndex) {
  217. GameConst.iconIndex = 4;
  218. this.setNodeSelectScenePos(GameConst.iconIndex);
  219. }
  220. }
  221. onClickLeftBtn() {
  222. GameMgr.Inst.sendEvent(UI_NAME.Start, "点击左切换按钮");
  223. GameConst.iconIndex--;
  224. this.setNodeSelectScenePos(GameConst.iconIndex);
  225. }
  226. onClickRightBtn() {
  227. GameMgr.Inst.sendEvent(UI_NAME.Start, "点击右切换按钮");
  228. GameConst.iconIndex++;
  229. this.setNodeSelectScenePos(GameConst.iconIndex);
  230. }
  231. setNodeSelectScenePos(iconIndex: number) {
  232. //let maxLeftX = GameConst.maxIconIndex * 750 * 0.5 - 750 * 0.5;
  233. let maxLeftX = this.node_scene.width * 0.5 - 750 * 0.5;
  234. let x = maxLeftX - (iconIndex) * 750;
  235. this.node_leftBtn.off(cc.Node.EventType.TOUCH_END, this.onClick, this);
  236. this.node_rightBtn.off(cc.Node.EventType.TOUCH_END, this.onClick, this);
  237. cc.tween(this.node_scene).to(0.5, { x: x }).call(() => {
  238. this.node_leftBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  239. this.node_rightBtn.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
  240. }).start();
  241. mk.console.log("GameConst.iconIndex", GameConst.iconIndex, x);
  242. this.node_leftBtn.active = GameConst.iconIndex > 0;
  243. this.node_rightBtn.active = GameConst.iconIndex < GameConst.maxIconIndex;
  244. }
  245. /**点击分享按钮 */
  246. onClickShareBtn() {
  247. }
  248. /**点击存钱罐按钮 */
  249. onClickBankBtn() {
  250. }
  251. /**点击福袋按钮 */
  252. onClickLuckyPacketBtn() {
  253. }
  254. /**点击签到按钮 */
  255. onClickSignBtn() {
  256. }
  257. /** 设置更多游戏图片 */
  258. setMoreGameSp(arr) {
  259. let len = arr.length
  260. let index = Util.rnd(0, len - 1)
  261. let data = arr[index]
  262. this.showMoreGameSp(data)
  263. this.schedule(() => {
  264. index++
  265. index = (index % len)
  266. // LogUtil.logV('setMoreGameSp ', 'index ' + index)
  267. data = arr[index]
  268. this.showMoreGameSp(data)
  269. }, 10)
  270. }
  271. showMoreGameSp(data) {
  272. // LoadResUtil.loadRemoteSprite(data.icon, this.spr_moreGame, () => {
  273. // this.label_moreGameName.string = data.title
  274. // })
  275. }
  276. //自定义事件---------------------------------------------------------------------
  277. /**微信授权返回 */
  278. onWxAuthBack() {
  279. this.initHead();
  280. this.initNickName();
  281. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  282. }
  283. }