using UI.CommonGame; using FairyGUI; using ET; 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((EventCallback0)(() => { int luckyBoxId = LuckyBoxDataManager.Instance.currentBoxId; LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId); ItemUtil.ExchangeItemById(luckyBoxCfg.costID, 10, true); })); } public void Dispose() { if (_valueBar != null) { _valueBar.Dispose(); } _valueBar = null; } public void OnShown() { UpdateNumeric(); UpdateCJExchange(); UpdateCJ(LuckyBoxDataManager.Instance.currentBoxId); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric); EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } public void Controller(int ctrlSelected) { _valueBar.m_c1.selectedIndex = ctrlSelected; } public void OnHide() { EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNumeric); EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItem); } private void UpdateItem() { UpdateCJExchange(); UpdateCJ(LuckyBoxDataManager.Instance.currentBoxId); } private void UpdateNumeric() { _valueBar.m_btnGold.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Gold); _valueBar.m_btnPower.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Power); _valueBar.m_btnDiamondPurple.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondP); _valueBar.m_btnDiamondRed.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.DiamondR); } //ÕªÐÇ£¨³é½±£©¶Ò»» private void UpdateCJExchange() { int luckyBoxId1 = LuckyBoxDataManager.BOX_ID_2; LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1); _valueBar.m_btnCJLuoXing.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.bonusArr[0][0]); _valueBar.m_btnCJLuoXing.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.bonusArr[0][0]).res); int luckyBoxId2 = LuckyBoxDataManager.BOX_ID_1; LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2); _valueBar.m_btnCJHuoDong.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.bonusArr[0][0]); _valueBar.m_btnCJHuoDong.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.bonusArr[0][0]).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); } } }