import Gamecfg from "../../../../common/gameCfg"; import { gameMethod } from "../../../../common/gameMethod"; import GameDataCenter from "../../../../data/GameDataCenter"; import { ItemEvent, UserEvent, ZhanLiEvent } from "../../../../data/const/EventConst"; import { ConstItem, HeadBgType, ItemKind } from "../../../../data/const/TypeConst"; import FguiLoadMgr from "../../../../frameWork/fgui/FguiLoadMgr"; import EventMng from "../../../../manager/EventMng"; import ClickAuEffect from "../../../../utils/ClickAuEffect"; import GameMath from "../../../../utils/GameMath"; import { GridEvent } from "../../../gridMap/GridEvent"; import ItemCount, { ItemCountExtraParam } from "../../Common/ItemCount"; import UserHead from "../../Common/UserHead"; export default class UIHeadTopView { private _HeadBtn: fairygui.GObject; private _LevelFont: fairygui.GObject; private _NameFont: fairygui.GObject; private _ZhanLiFont: fairygui.GObject; private _UserHead: UserHead; private _PbLv: fairygui.GProgressBar; ItemGold: ItemCount; ItemDiamond: ItemCount; ItemSp: ItemCount; public constructor(vm: fgui.GComponent) { this._HeadBtn = vm.getChild("HeadBtn") this._NameFont = vm.getChild("NameFont") this._LevelFont = vm.getChild("LevelFont") this._ZhanLiFont = vm.getChild("ZhanLiFont") this._UserHead = vm.getChild("UserHead") as UserHead; this._PbLv = vm.getChild("PbLv") as fgui.GProgressBar; this.ItemGold = new ItemCount(vm.getChild("ItemGold") as fgui.GButton); this.ItemDiamond = new ItemCount(vm.getChild("ItemDiamond") as fgui.GButton); this.ItemSp = new ItemCount(vm.getChild("ItemSp") as fgui.GButton); // FguiLoadMgr.loadItemIcon(vm.getChild("GoldImg").asLoader, ConstItem.coin, () => { }, 0.3); // FguiLoadMgr.loadItemIcon(vm.getChild("DiamondImg").asLoader, ConstItem.gem, () => { }, 0.3); } public onEnable(): void { this.ItemGold.onEnable(); this.ItemDiamond.onEnable(); this.ItemSp.onEnable(); GameDataCenter.item.sendItemInfo(); EventMng.on(ItemEvent.UP_ITEM, this.onUpItem, this) EventMng.on(GridEvent.HC_SP_UP, this.onUpSp, this) EventMng.on(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this) EventMng.on(UserEvent.SET_NAME_SUCC, this.onUpUser, this); EventMng.on(UserEvent.UP_USER, this.onUpUser, this); this._HeadBtn.onClick(this.OnClickHeadBtn, this) this.onUpUser() this.onUpZhanLi(); this.onUpRed(); } public onDisable(): void { this.ItemGold.onDisable(); this.ItemDiamond.onDisable(); this.ItemSp.onDisable(); EventMng.off(ItemEvent.UP_ITEM, this.onUpItem, this) EventMng.off(GridEvent.HC_SP_UP, this.onUpSp, this) EventMng.off(ZhanLiEvent.ZHANLI_UP_HOME_ZHANLI, this.onUpZhanLi, this) EventMng.off(UserEvent.SET_NAME_SUCC, this.onUpUser, this); EventMng.off(UserEvent.UP_USER, this.onUpUser, this); this._HeadBtn.offClick(this.OnClickHeadBtn, this) } @ClickAuEffect() private OnClickHeadBtn() { // let conf = Gamecfg.taskMain.getItem(GameDataCenter.sevBack.actTaskMain?.id?.toString()); // if (!gameMethod.isEmpty(conf) && conf.kind == TaskKind.changeName && !GameDataCenter.task.curTaskIsFinish()) { // //当前是改名任务并且未完成,直接打开改名界面 // GameDataCenter.user.sendIntoSetName(() => { // FguiMgr.Instance.openUI(SetGenderView, ViewZorder.FULL); // }) // } else { // FguiMgr.Instance.openUI(SetViewView, ViewZorder.FULL) // } } onUpUser() { let user = GameDataCenter.user?.userInfo; this._NameFont.text = user?.name let lv = user?.level this._LevelFont.text = "Lv." + lv; let curLvCfg = Gamecfg.levelLevel.getItem(lv.toString()); this._PbLv.max = curLvCfg?.exp; this._PbLv.value = user?.exp; this._UserHead.setHead({ userInfo: user, colorBg: HeadBgType.purple, isFlip: false }); } onUpItem() { let param: ItemCountExtraParam = { showAddBtn: true, fullNumberShow: true, isBuyItem: true, notEnoughRed: false } let goldInfo = GameDataCenter.item.getKindItem(ConstItem.coin); this.ItemGold.setData(goldInfo, null, param); let gemInfo = GameDataCenter.item.getKindItem(ConstItem.gem); this.ItemDiamond.setData(gemInfo, null, param); } onUpSp() { //体力单独读取 let spInfo = [ConstItem.sp[0], ConstItem.sp[1], GameDataCenter.gridMap.hcInfo?.tili]; let param: ItemCountExtraParam = { showAddBtn: true, fullNumberShow: true, isBuyItem: true, notEnoughRed: false } this.ItemSp.setData(spInfo, null, param); } onUpZhanLi() { this._ZhanLiFont.asTextField.text = GameMath.showNum(GameDataCenter.user?.userInfo?.power) } /** 更新红点 */ onUpRed() { } }