UIHeadTopView.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import Gamecfg from "../../../../common/gameCfg";
  2. import { gameMethod } from "../../../../common/gameMethod";
  3. import GameDataCenter from "../../../../data/GameDataCenter";
  4. import { ItemEvent, UserEvent, ZhanLiEvent } from "../../../../data/const/EventConst";
  5. import { ConstItem, HeadBgType, ItemKind } from "../../../../data/const/TypeConst";
  6. import FguiLoadMgr from "../../../../frameWork/fgui/FguiLoadMgr";
  7. import EventMng from "../../../../manager/EventMng";
  8. import ClickAuEffect from "../../../../utils/ClickAuEffect";
  9. import GameMath from "../../../../utils/GameMath";
  10. import { GridEvent } from "../../../gridMap/GridEvent";
  11. import ItemCount, { ItemCountExtraParam } from "../../Common/ItemCount";
  12. import UserHead from "../../Common/UserHead";
  13. export default class UIHeadTopView {
  14. private _HeadBtn: fairygui.GObject;
  15. private _LevelFont: fairygui.GObject;
  16. private _NameFont: fairygui.GObject;
  17. private _ZhanLiFont: fairygui.GObject;
  18. private _UserHead: UserHead;
  19. private _PbLv: fairygui.GProgressBar;
  20. ItemGold: ItemCount;
  21. ItemDiamond: ItemCount;
  22. ItemSp: fairygui.GProgressBar;
  23. public constructor(vm: fgui.GComponent) {
  24. this._HeadBtn = vm.getChild("HeadBtn")
  25. this._NameFont = vm.getChild("NameFont")
  26. this._LevelFont = vm.getChild("LevelFont")
  27. this._ZhanLiFont = vm.getChild("ZhanLiFont")
  28. this._UserHead = vm.getChild("UserHead") as UserHead;
  29. this._PbLv = vm.getChild("PbLv") as fgui.GProgressBar;
  30. this.ItemGold = new ItemCount(vm.getChild("ItemGold") as fgui.GButton);
  31. this.ItemDiamond = new ItemCount(vm.getChild("ItemDiamond") as fgui.GButton);
  32. this.ItemSp = vm.getChild("ItemSp") as fgui.GProgressBar;
  33. // FguiLoadMgr.loadItemIcon(vm.getChild("GoldImg").asLoader, ConstItem.coin, () => { }, 0.3);
  34. // FguiLoadMgr.loadItemIcon(vm.getChild("DiamondImg").asLoader, ConstItem.gem, () => { }, 0.3);
  35. }
  36. public onEnable(): void {
  37. this.ItemGold.onEnable();
  38. this.ItemDiamond.onEnable();
  39. GameDataCenter.item.sendItemInfo();
  40. EventMng.on(ItemEvent.UP_ITEM, this.onUpItem, this)
  41. EventMng.on(GridEvent.HC_SP_UP, this.onUpSp, this)
  42. EventMng.on(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this)
  43. EventMng.on(UserEvent.SET_NAME_SUCC, this.onUpUser, this);
  44. EventMng.on(UserEvent.UP_USER, this.onUpUser, this);
  45. this._HeadBtn.onClick(this.OnClickHeadBtn, this)
  46. this.onUpUser()
  47. this.onUpZhanLi();
  48. this.onUpRed();
  49. }
  50. public onDisable(): void {
  51. this.ItemGold.onDisable();
  52. this.ItemDiamond.onDisable();
  53. EventMng.off(ItemEvent.UP_ITEM, this.onUpItem, this)
  54. EventMng.off(GridEvent.HC_SP_UP, this.onUpSp, this)
  55. EventMng.off(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this)
  56. EventMng.off(UserEvent.SET_NAME_SUCC, this.onUpUser, this);
  57. EventMng.off(UserEvent.UP_USER, this.onUpUser, this);
  58. this._HeadBtn.offClick(this.OnClickHeadBtn, this)
  59. }
  60. @ClickAuEffect()
  61. private OnClickHeadBtn() {
  62. // let conf = Gamecfg.taskMain.getItem(GameDataCenter.sevBack.actTaskMain?.id?.toString());
  63. // if (!gameMethod.isEmpty(conf) && conf.kind == TaskKind.changeName && !GameDataCenter.task.curTaskIsFinish()) {
  64. // //当前是改名任务并且未完成,直接打开改名界面
  65. // GameDataCenter.user.sendIntoSetName(() => {
  66. // FguiMgr.Instance.openUI(SetGenderView, ViewZorder.FULL);
  67. // })
  68. // } else {
  69. // FguiMgr.Instance.openUI(SetViewView, ViewZorder.FULL)
  70. // }
  71. }
  72. onUpUser() {
  73. let user = GameDataCenter.user?.userInfo;
  74. this._NameFont.text = user?.name
  75. let lv = user?.level
  76. this._LevelFont.text = "Lv." + lv;
  77. let curLvCfg = Gamecfg.levelLevel.getItem(lv.toString());
  78. this._PbLv.max = curLvCfg?.exp;
  79. this._PbLv.value = user?.exp;
  80. this._UserHead.setHead({ userInfo: user, colorBg: HeadBgType.purple, isFlip: false });
  81. }
  82. onUpItem() {
  83. let param: ItemCountExtraParam = {
  84. showAddBtn: true,
  85. fullNumberShow: true,
  86. isBuyItem: true,
  87. notEnoughRed: false
  88. }
  89. let goldInfo = GameDataCenter.item.getKindItem(ConstItem.coin);
  90. this.ItemGold.setData(goldInfo, null, param, "ui://Home/Btn_zjm_jinbi");
  91. let gemInfo = GameDataCenter.item.getKindItem(ConstItem.gem);
  92. this.ItemDiamond.setData(gemInfo, null, param, "ui://Home/Btn_zjm_zuanshi");
  93. }
  94. onUpSp() {
  95. //体力单独读取
  96. let hcInfo = GameDataCenter.gridMap?.hcInfo;
  97. this.ItemSp.max = hcInfo?.maxTili;
  98. this.ItemSp.value = hcInfo?.tili;
  99. }
  100. onUpZhanLi() {
  101. this._ZhanLiFont.asTextField.text = GameMath.showNum(GameDataCenter.user?.userInfo?.power)
  102. }
  103. /** 更新红点 */
  104. onUpRed() {
  105. }
  106. }