HallUI.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { _decorator, tween, v3, sp } from 'cc';
  2. import BasePanel from '../../core/component/BasePanel';
  3. import Data from '../../core/manager/Data';
  4. import WindowManager from '../../core/manager/WindowManager';
  5. import GameConst, { BOX_TYPE } from '../../core/common/GameConst';
  6. import Utils from '../../core/utils/Utils';
  7. import MsgHints from '../../core/utils/MsgHints';
  8. import { BoxLayer } from './gameui/BoxLayer';
  9. import { constants } from 'db://assets/data/constants';
  10. import audioManager from 'db://assets/manager/audioManager';
  11. import platformSystem from 'db://assets/platform/platformSystem';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('HallUI')
  14. export class HallUI extends BasePanel {
  15. onBtnClicked(event: any, customEventData: any) {
  16. audioManager.playOneShot(constants.audios.btnclick);
  17. var btnName = event.target.name;
  18. switch (btnName) {
  19. case "btn_setting":
  20. // WindowManager.ins.open("NewPackOpenedLayer");
  21. WindowManager.ins.open("SettingLayer")
  22. break;
  23. case "btn_play":
  24. WindowManager.ins.open("LevelLayer");
  25. /*platformSystem.platform.showRewardVideo((b) => {
  26. WindowManager.ins.open("LevelLayer");
  27. })*/
  28. break;
  29. case "btn_buy_life":
  30. if (Data.user.life >= GameConst.MAX_LIFE) {
  31. MsgHints.show("体力已满")
  32. return;
  33. }
  34. WindowManager.ins.open("BuyLifeLayer")
  35. break;
  36. case "btn_buy_coin":
  37. WindowManager.ins.open("BuyCoinLayer");
  38. break;
  39. case "full0":
  40. let info = Data.user.hasLvBox();
  41. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  42. com.setInfo(BOX_TYPE.LEVEL, GameConst.getLvBoxReward(Math.floor(Data.user.lv / 10)))
  43. });
  44. break;
  45. case "full1":
  46. info = Data.user.hasStarBox();
  47. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  48. com.setInfo(BOX_TYPE.STAR, GameConst.getStarBoxReward(Math.floor(Data.user.lv / 1000)))
  49. });
  50. break;
  51. }
  52. }
  53. start() {
  54. this.SetProgressBar("probar_lv", 0.1);
  55. let btn_play = this.GetNode("btn_play")
  56. tween(btn_play).sequence(tween(btn_play).to(1, { scale: v3(1.05, 1.05, 1.05) }), tween(btn_play).to(1, { scale: v3(1, 1, 1) })).repeatForever().start()
  57. Utils.loadRes('effect_hecheng', "spine", sp.SkeletonData)
  58. }
  59. update() {
  60. if (Data.user.life >= GameConst.MAX_LIFE) {
  61. this.SetText("lbl_life_time", "已满")
  62. }else {
  63. if (Data.user.life_cost_time == 0) {
  64. Data.user.life_cost_time = Date.now();
  65. }
  66. let nLeft = (Date.now() - Data.user.life_cost_time) / 1000;
  67. let addLife = Math.floor(nLeft / 60 / GameConst.MAX_LIFE_RECOVERY_TIME);
  68. if (addLife > 0)
  69. Data.user.life += addLife;
  70. nLeft -= addLife * GameConst.MAX_LIFE_RECOVERY_TIME * 60;
  71. this.SetText("lbl_life_time", Utils.getTimeStrByS(GameConst.MAX_LIFE_RECOVERY_TIME * 60 - nLeft))
  72. }
  73. this.SetText("lbl_life", Data.user.life + "")
  74. this.SetText("lbl_coin", Data.user.coin + "")
  75. this.SetText("lbl_lv", Data.user.lv + "")
  76. this.SetText("lbl_lv_center", Data.user.lv + "")
  77. let info = Data.user.hasLvBox();
  78. this.GetGameObject("full0").active = info
  79. let lvmin = Data.user.lv % 10;
  80. this.SetText("lbl_pro_lv", lvmin + "/10");
  81. this.SetProgressBar("lbl_pro_star", lvmin / 10);
  82. this.SetProgressBar("probar_lv_center", lvmin / 10);
  83. this.SetProgressBar("probar_lv", lvmin / 10);
  84. info = Data.user.hasStarBox();
  85. if (info) {
  86. this.SetText("probar_star", "满");
  87. this.SetProgressBar("probar_star", 1);
  88. this.GetGameObject("full1").active = true;
  89. }else {
  90. let starmin = Data.user.star % 1000;
  91. this.GetGameObject("full1").active = false;
  92. this.SetText("lbl_pro_star", starmin + "/1000");
  93. this.SetProgressBar("probar_star", starmin / 1000);
  94. }
  95. }
  96. }