using UI.CommonGame; using FairyGUI; namespace GFGGame { public class ValueBarController { private UI_ComponentValueBar _valueBar; public ValueBarController(GComponent valueBar, int ctrlSelected = 0) { _valueBar = UI_ComponentValueBar.Create(valueBar); _valueBar.m_c1.selectedIndex = ctrlSelected; // _valueBar.target.x = 370; _valueBar.m_btnGold.onClick.Add(() => { ItemUtil.AddGold(); }); _valueBar.m_btnPower.onClick.Add(() => { ItemUtil.AddPower(); }); _valueBar.m_btnDiamondPurple.onClick.Add(() => { ItemUtil.AddDiamondPurple(); }); _valueBar.m_btnDiamondRed.onClick.Add(() => { ItemUtil.AddDiamondRed(); }); _valueBar.m_btnCJLuoXing.onClick.Add(() => { ViewManager.Show(ViewName.LUCKY_BOX_VIEW); }); _valueBar.m_btnCJHuoDong.onClick.Add(() => { ViewManager.Show(ViewName.LUCKY_BOX_VIEW); }); _valueBar.m_btnCJ.onClick.Add(() => { int luckyBoxId = LuckyBoxBonusDataCache.currentBoxId; LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId); CurrencyRatioCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(luckyBoxCfg.costID); ItemUtil.ExchangeItemById(luckyBoxCfg.costID, currencyRatioCfg != null ? currencyRatioCfg.num : 20, true); }); } public void Dispose() { if (_valueBar != null) { _valueBar.Dispose(); } _valueBar = null; } public void OnShown() { UpdateGold(); UpdatePower(); UpdateDiamondPurple(); UpdateDiamondRed(); UpdateCJExchange(); UpdateCJ(LuckyBoxBonusDataCache.currentBoxId); EventAgent.AddEventListener(ConstMessage.ROLE_GOLD_CHANGED, UpdateGold); EventAgent.AddEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdatePower); EventAgent.AddEventListener(ConstMessage.ROLE_DIAMOND_PURPLE_CHANGED, UpdateDiamondPurple); EventAgent.AddEventListener(ConstMessage.ROLE_DIAMOND_RED_CHANGED, UpdateDiamondRed); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } public void Controller(int ctrlSelected) { _valueBar.m_c1.selectedIndex = ctrlSelected; } public void OnHide() { EventAgent.RemoveEventListener(ConstMessage.ROLE_GOLD_CHANGED, UpdateGold); EventAgent.RemoveEventListener(ConstMessage.ROLE_POWER_CHANGED, UpdatePower); EventAgent.RemoveEventListener(ConstMessage.ROLE_DIAMOND_PURPLE_CHANGED, UpdateDiamondPurple); EventAgent.RemoveEventListener(ConstMessage.ROLE_DIAMOND_RED_CHANGED, UpdateDiamondRed); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } private void UpdateItem() { UpdateCJExchange(); UpdateCJ(LuckyBoxBonusDataCache.currentBoxId); } private void UpdateGold() { _valueBar.m_btnGold.text = "" + RoleDataManager.gold; EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.gold); } private void UpdatePower() { _valueBar.m_btnPower.text = "" + RoleDataManager.power; EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.power); } private void UpdateDiamondPurple() { _valueBar.m_btnDiamondPurple.text = "" + RoleDataManager.diaP; EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.diaP); } private void UpdateDiamondRed() { _valueBar.m_btnDiamondRed.text = "" + RoleDataManager.diaR; EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.diaR); } //ÕªÐÇ£¨³é½±£©¶Ò»» private void UpdateCJExchange() { int luckyBoxId1 = LuckyBoxDataManager.BOX_ID_2; LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1); _valueBar.m_btnCJLuoXing.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.drop); _valueBar.m_btnCJLuoXing.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.drop).res); int luckyBoxId2 = LuckyBoxDataManager.BOX_ID_1; LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2); _valueBar.m_btnCJHuoDong.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.drop); _valueBar.m_btnCJHuoDong.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.drop).res); } public void UpdateCJ(int id) { LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(id); if (luckyBoxCfg == null) return; _valueBar.m_btnCJ.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg.costID); _valueBar.m_btnCJ.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res); } } }