HallUI.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { _decorator, tween, v3, sp, EditBox } from 'cc';
  2. import BasePanel from '../core/component/BasePanel';
  3. import { audioMgr } from '../core/manager/AudioManager';
  4. import Data from '../core/manager/Data';
  5. import WindowManager from '../core/manager/WindowManager';
  6. import MsgHints from '../core/utils/MsgHints';
  7. import Utils from '../core/utils/Utils';
  8. import { BoxLayer } from '../gameui/BoxLayer';
  9. import { GameConst, BOX_TYPE } from '../core/common/GameConst';
  10. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('HallUI')
  13. export class HallUI extends BasePanel {
  14. @property({type:EditBox})
  15. public editBox: EditBox = null!;
  16. onBtnClicked(event: any, customEventData: any) {
  17. audioMgr.playOneShot(GameConst.audios.btnclick);
  18. var btnName = event.target.name;
  19. switch (btnName) {
  20. case "btn_setting":
  21. // WindowManager.ins.open("NewPackOpenedLayer");
  22. WindowManager.ins.open("SettingLayer")
  23. break;
  24. case "btn_play":
  25. //获取输入的内容
  26. if(GameConst.isDebug){
  27. let str: string = this.editBox.string;
  28. if(!Utils.isNull(str)){
  29. const level: number = parseInt(str);
  30. Data.user.lv = level;
  31. }
  32. }
  33. WindowManager.ins.open("LevelLayer");
  34. /*platformSystem.platform.showRewardVideo((b) => {
  35. WindowManager.ins.open("LevelLayer");
  36. })*/
  37. break;
  38. case "btn_buy_life":
  39. if (Data.user.life >= GameConst.MAX_LIFE) {
  40. MsgHints.show(i18n("main.体力已满"))
  41. return;
  42. }
  43. WindowManager.ins.open("BuyLifeLayer")
  44. break;
  45. case "btn_buy_coin":
  46. WindowManager.ins.open("BuyCoinLayer");
  47. break;
  48. case "full0":
  49. let info = Data.user.hasLvBox();
  50. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  51. com.setInfo(BOX_TYPE.LEVEL, GameConst.getLvBoxReward(Math.floor(Data.user.lv / 10)))
  52. });
  53. break;
  54. case "full1":
  55. info = Data.user.hasStarBox();
  56. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  57. com.setInfo(BOX_TYPE.STAR, GameConst.getStarBoxReward(Math.floor(Data.user.lv / 1000)))
  58. });
  59. break;
  60. }
  61. }
  62. start() {
  63. if(!GameConst.isDebug){
  64. this.editBox.node.active = false;
  65. }
  66. this.SetText("level_lable", i18n("main.LV:%{value}", { value: Data.user.lv}));
  67. this.SetProgressBar("probar_lv", 0.1);
  68. let btn_play = this.GetNode("btn_play")
  69. 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()
  70. }
  71. update() {
  72. if (Data.user.life >= GameConst.MAX_LIFE) {
  73. this.SetText("lbl_life_time", i18n("main.已满"))
  74. }else {
  75. if (Data.user.life_cost_time == 0) {
  76. Data.user.life_cost_time = Date.now();
  77. }
  78. let nLeft = (Date.now() - Data.user.life_cost_time) / 1000;
  79. let addLife = Math.floor(nLeft / 60 / GameConst.MAX_LIFE_RECOVERY_TIME);
  80. if (addLife > 0)
  81. Data.user.life += addLife;
  82. nLeft -= addLife * GameConst.MAX_LIFE_RECOVERY_TIME * 60;
  83. this.SetText("lbl_life_time", Utils.getTimeStrByS(GameConst.MAX_LIFE_RECOVERY_TIME * 60 - nLeft))
  84. }
  85. this.SetText("lbl_life", Data.user.life + "")
  86. this.SetText("lbl_coin", Data.user.coin + "")
  87. this.SetText("lbl_lv", Data.user.lv + "")
  88. this.SetText("lbl_lv_center", Data.user.lv + "")
  89. let info = Data.user.hasLvBox();
  90. this.GetGameObject("full0").active = info
  91. let lvmin = Data.user.lv % 10;
  92. this.SetText("lbl_pro_lv", lvmin + "/10");
  93. this.SetProgressBar("lbl_pro_star", lvmin / 10);
  94. this.SetProgressBar("probar_lv_center", lvmin / 10);
  95. this.SetProgressBar("probar_lv", lvmin / 10);
  96. info = Data.user.hasStarBox();
  97. if (info) {
  98. this.SetText("probar_star", "满");
  99. this.SetProgressBar("probar_star", 1);
  100. this.GetGameObject("full1").active = true;
  101. }else {
  102. let starmin = Data.user.star % 1000;
  103. this.GetGameObject("full1").active = false;
  104. this.SetText("lbl_pro_star", starmin + "/1000");
  105. this.SetProgressBar("probar_star", starmin / 1000);
  106. }
  107. }
  108. }