123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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: fairygui.GProgressBar;
- 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 = vm.getChild("ItemSp") as fgui.GProgressBar;
- // 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();
- 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();
- 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, "ui://Home/Btn_zjm_jinbi");
- let gemInfo = GameDataCenter.item.getKindItem(ConstItem.gem);
- this.ItemDiamond.setData(gemInfo, null, param, "ui://Home/Btn_zjm_zuanshi");
- }
- onUpSp() {
- //体力单独读取
- let hcInfo = GameDataCenter.gridMap?.hcInfo;
- this.ItemSp.max = hcInfo?.maxTili;
- this.ItemSp.value = hcInfo?.tili;
- }
- onUpZhanLi() {
- this._ZhanLiFont.asTextField.text = GameMath.showNum(GameDataCenter.user?.userInfo?.power)
- }
- /** 更新红点 */
- onUpRed() {
- }
- }
|