UIHeadTopView.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: ItemCount;
  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 = new ItemCount(vm.getChild("ItemSp") as fgui.GButton);
  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. this.ItemSp.onEnable();
  40. GameDataCenter.item.sendItemInfo();
  41. EventMng.on(ItemEvent.UP_ITEM, this.onUpItem, this)
  42. EventMng.on(GridEvent.HC_SP_UP, this.onUpSp, this)
  43. EventMng.on(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this)
  44. EventMng.on(UserEvent.SET_NAME_SUCC, this.onUpUser, this);
  45. EventMng.on(UserEvent.UP_USER, this.onUpUser, this);
  46. this._HeadBtn.onClick(this.OnClickHeadBtn, this)
  47. this.onUpUser()
  48. this.onUpZhanLi();
  49. this.onUpRed();
  50. }
  51. public onDisable(): void {
  52. this.ItemGold.onDisable();
  53. this.ItemDiamond.onDisable();
  54. this.ItemSp.onDisable();
  55. EventMng.off(ItemEvent.UP_ITEM, this.onUpItem, this)
  56. EventMng.off(GridEvent.HC_SP_UP, this.onUpSp, this)
  57. EventMng.off(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this)
  58. EventMng.off(UserEvent.SET_NAME_SUCC, this.onUpUser, this);
  59. EventMng.off(UserEvent.UP_USER, this.onUpUser, this);
  60. this._HeadBtn.offClick(this.OnClickHeadBtn, this)
  61. }
  62. @ClickAuEffect()
  63. private OnClickHeadBtn() {
  64. // let conf = Gamecfg.taskMain.getItem(GameDataCenter.sevBack.actTaskMain?.id?.toString());
  65. // if (!gameMethod.isEmpty(conf) && conf.kind == TaskKind.changeName && !GameDataCenter.task.curTaskIsFinish()) {
  66. // //当前是改名任务并且未完成,直接打开改名界面
  67. // GameDataCenter.user.sendIntoSetName(() => {
  68. // FguiMgr.Instance.openUI(SetGenderView, ViewZorder.FULL);
  69. // })
  70. // } else {
  71. // FguiMgr.Instance.openUI(SetViewView, ViewZorder.FULL)
  72. // }
  73. }
  74. onUpUser() {
  75. let user = GameDataCenter.user?.userInfo;
  76. this._NameFont.text = user?.name
  77. let lv = user?.level
  78. this._LevelFont.text = "Lv." + lv;
  79. let curLvCfg = Gamecfg.levelLevel.getItem(lv.toString());
  80. this._PbLv.max = curLvCfg?.exp;
  81. this._PbLv.value = user?.exp;
  82. this._UserHead.setHead({ userInfo: user, colorBg: HeadBgType.purple, isFlip: false });
  83. }
  84. onUpItem() {
  85. let param: ItemCountExtraParam = {
  86. showAddBtn: true,
  87. fullNumberShow: true,
  88. isBuyItem: true,
  89. notEnoughRed: false
  90. }
  91. let goldInfo = GameDataCenter.item.getKindItem(ConstItem.coin);
  92. this.ItemGold.setData(goldInfo, null, param);
  93. let gemInfo = GameDataCenter.item.getKindItem(ConstItem.gem);
  94. this.ItemDiamond.setData(gemInfo, null, param);
  95. }
  96. onUpSp() {
  97. //体力单独读取
  98. let spInfo = [ConstItem.sp[0], ConstItem.sp[1], GameDataCenter.gridMap.hcInfo?.tili];
  99. let param: ItemCountExtraParam = {
  100. showAddBtn: true,
  101. fullNumberShow: true,
  102. isBuyItem: true,
  103. notEnoughRed: false
  104. }
  105. this.ItemSp.setData(spInfo, null, param);
  106. }
  107. onUpZhanLi() {
  108. this._ZhanLiFont.asTextField.text = GameMath.showNum(GameDataCenter.user?.userInfo?.power)
  109. }
  110. /** 更新红点 */
  111. onUpRed() {
  112. }
  113. }