HallUI.ts 4.9 KB

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