public override void OnShow(object msg) { base.OnShow(msg); if (msg != null) { m_ShopParameter = (OpenShopParameter)msg; } m_ItemConfig = m_CfgEternityProxy.GetItemByKey(m_ShopParameter.Tid); m_Bounds = m_ShopParameter.Bounds; if (m_ShopParameter.MoneyType == 1) { m_Money = (int)CurrencyUtil.GetGameCurrencyCount(); } else { m_Money = (int)CurrencyUtil.GetRechargeCurrencyCount(); } if (m_ShopParameter.OperateType == 1) { m_Max = m_ShopParameter.LimitCount; } else { GetGoodMax(); if (m_Max == 0) { m_Min = 0; } } m_GoodName.text = TableUtil.GetItemName(m_ShopParameter.Tid); m_GoodName.color = ColorUtil.GetColorByItemQuality(m_ItemConfig.Quality); UIUtil.SetIconImage(m_MoneyIcon, TableUtil.GetItemIconBundle((KNumMoneyType)m_ShopParameter.MoneyType), TableUtil.GetItemIconImage((KNumMoneyType)m_ShopParameter.MoneyType)); m_InputBox.onValueChanged.RemoveAllListeners(); m_CurrentNum = m_Bounds; m_InputBox.text = m_Bounds.ToString(); m_TotalPrice.text = Mathf.CeilToInt(m_CurrentNum * (m_ShopParameter.Price / m_ShopParameter.Bounds)).ToString(); m_InputBox.onValueChanged.AddListener((str) => { if (str.Length > 0) { m_CurrentNum = int.Parse(str); if (m_CurrentNum < m_Min) { m_CurrentNum = m_Min; } else if (m_CurrentNum > m_Max) { m_CurrentNum = m_Max; } m_InputBox.text = m_CurrentNum.ToString(); m_BtnLeft.GetComponent <Button>().interactable = m_CurrentNum > m_Bounds; m_BtnRight.GetComponent <Button>().interactable = m_CurrentNum < m_Max; SetHotKeyEnabled("left", m_CurrentNum > m_Bounds); SetHotKeyEnabled("Right", m_CurrentNum < m_Max); int m_Price = Mathf.CeilToInt(m_CurrentNum * (m_ShopParameter.Price / m_ShopParameter.Bounds)); m_TotalPrice.text = m_Price.ToString(); if (m_ShopParameter.OperateType != 1) { SetHotKeyEnabled("confirm", m_Money >= m_Price && m_CurrentNum > 0); } else { SetHotKeyEnabled("confirm", true); } } else { m_CurrentNum = 0; int m_Price = 0; m_TotalPrice.text = m_Price.ToString(); SetHotKeyEnabled("confirm", false); } }); UIEventListener.UIEventListener.AttachListener(m_BtnLeft).onDown = OnLeftDonw; UIEventListener.UIEventListener.AttachListener(m_BtnLeft).onUp = OnUp; UIEventListener.UIEventListener.AttachListener(m_BtnRight).onDown = OnRightDown; UIEventListener.UIEventListener.AttachListener(m_BtnRight).onUp = OnUp; }
protected override void OnCellRenderer(int groupIndex, int cellIndex, object cellData, RectTransform cellView, bool selected) { Animator m_Animator = cellView.GetComponent <Animator>(); if (m_Animator) { m_Animator.SetBool("IsOn", selected); } UIViewListLayout style = State.GetPageLayoutStyle(State.GetPageIndex()); if (State.GetPageIndex() == 0) { ShopWindowVO m_ShopWindowVO = (ShopWindowVO)cellData; NpcShopElementGrid m_ShopElementGrid = cellView.GetOrAddComponent <NpcShopElementGrid>(); if (style == UIViewListLayout.Grid) { m_ShopElementGrid.SetData(m_ShopWindowVO, selected, false); } else { m_ShopElementGrid.SetData(m_ShopWindowVO, selected, true); } CountDownCompent m_CountDownCompent = cellView.GetOrAddComponent <CountDownCompent>(); m_CountDownCompent.SetTime(m_ShopWindowVO.RefreshTime); if (selected) { if (m_ShopWindowVO.IsOpen == 0 || m_ShopWindowVO.ServerLeftNum == 0 || !m_ShopElementGrid.MoneyeEnough() || m_ShopWindowVO.LimitCount == 0 || m_ShopWindowVO.LimitCount < m_ShopWindowVO.ShopItemConfig.Value.Bounds && m_ShopWindowVO.LimitCount > 0) { State.GetAction(UIAction.Shop_Buy).Enabled = false; } else { State.GetAction(UIAction.Shop_Buy).Enabled = true; } m_OpenShopParameter = new OpenShopParameter(); m_OpenShopParameter.OperateType = 0; m_OpenShopParameter.Tid = m_ShopWindowVO.Tid; m_OpenShopParameter.Id = m_ShopWindowVO.Oid; m_OpenShopParameter.MoneyType = m_ShopWindowVO.ShopItemConfig.Value.MoneyType; m_OpenShopParameter.Price = m_ShopWindowVO.ShopItemConfig.Value.BuyCost * m_ShopWindowVO.ShopItemConfig.Value.DisCount; m_OpenShopParameter.LimitCount = (int)m_ShopWindowVO.LimitCount; m_OpenShopParameter.Stock = (int)m_ShopWindowVO.ServerLeftNum; m_OpenShopParameter.Bounds = m_ShopWindowVO.ShopItemConfig.Value.Bounds; m_OpenShopParameter.Category = ItemTypeUtil.GetItemType(m_ShopWindowVO.ShopItemConfig.Value.ItemGood.Value.Type).MainType; } } else if (State.GetPageIndex() == 1) { ItemBase m_PackageItem = (ItemBase)cellData; NpcShopSellElementGrid m_SellElementGrid = cellView.GetOrAddComponent <NpcShopSellElementGrid>(); if (style == UIViewListLayout.Grid) { m_SellElementGrid.SetData(m_PackageItem, selected, false); } else { m_SellElementGrid.SetData(m_PackageItem, selected, true); } if (selected) { if (m_PackageItem.Replicas != null && m_PackageItem.Replicas.Count > 0) { State.GetAction(UIAction.Shop_Sell).Enabled = false; } else if (m_PackageItem.MainType == Category.Expendable) { State.GetAction(UIAction.Shop_Sell).Enabled = false; } else { State.GetAction(UIAction.Shop_Sell).Enabled = true; } m_OpenShopParameter = new OpenShopParameter(); m_OpenShopParameter.OperateType = 1; m_OpenShopParameter.Tid = m_PackageItem.TID; m_OpenShopParameter.Id = m_PackageItem.UID; if (m_PackageItem.ItemConfig.SellCurrency == 1100004) { m_OpenShopParameter.MoneyType = 1; } else { m_OpenShopParameter.MoneyType = 2; } m_OpenShopParameter.Price = (int)m_PackageItem.ItemConfig.MoneyPrice; m_OpenShopParameter.LimitCount = (int)m_PackageItem.Count; m_OpenShopParameter.Stock = (int)m_PackageItem.Count; m_OpenShopParameter.Bounds = 1; m_OpenShopParameter.Category = m_PackageItem.MainType; } } else { ShopSellBackVO m_SellBack = (ShopSellBackVO)cellData; CountDownCompent m_CountDownCompent = cellView.GetOrAddComponent <CountDownCompent>(); m_CountDownCompent.SetTime(m_SellBack.ExpireTime); NpcShopSellBackElementGrid m_SellElementGrid = cellView.GetOrAddComponent <NpcShopSellBackElementGrid>(); if (style == UIViewListLayout.Grid) { m_SellElementGrid.SetData(m_SellBack, false); } else { m_SellElementGrid.SetData(m_SellBack, true); } if (selected) { if (!m_SellElementGrid.MoneyeEnough()) { State.GetAction(UIAction.Shop_Buy).Enabled = false; } else { State.GetAction(UIAction.Shop_Buy).Enabled = true; } m_OpenShopParameter = new OpenShopParameter(); m_OpenShopParameter.OperateType = 2; m_OpenShopParameter.Tid = (uint)m_SellBack.Tid; m_OpenShopParameter.Id = m_SellBack.Uid; if (m_SellBack.ItemConfig.SellCurrency == 1100004) { m_OpenShopParameter.MoneyType = 1; } else { m_OpenShopParameter.MoneyType = 2; } m_OpenShopParameter.Price = m_SellBack.ItemConfig.BuybackPrice; m_OpenShopParameter.LimitCount = (int)m_SellBack.Num; m_OpenShopParameter.Stock = (int)m_SellBack.Num; m_OpenShopParameter.Bounds = 1; m_OpenShopParameter.Category = ItemTypeUtil.GetItemType(m_SellBack.ItemConfig.Type).MainType; } } }