protected override int Compare(UIViewSortKind kind, object a, object b) { int result; if (State.GetPageIndex() == 0) { left = a as ShopWindowVO; right = b as ShopWindowVO; return(result = (int)(left.Order - right.Order)); } return(0); }
/// <summary> ///添加商品橱窗数据及购买剩余量 /// </summary> /// <param name="oid"></param> /// <param name="shopWindowVO"></param> public void AddShopWindowData(ulong oid, ShopWindowVO shopWindowVO) { m_ShopWindowData.Add(oid, shopWindowVO); uint num; if (m_BuyRecordData.TryGetValue(oid, out num)) { if (shopWindowVO.ShopItemConfig.Value.IndividualLimitNum >= 0) { shopWindowVO.LimitCount = shopWindowVO.ShopItemConfig.Value.IndividualLimitNum - num; } if (shopWindowVO.LimitCount == 0) { shopWindowVO.IsOpen = 0; } } }
/// <summary> /// 同步商店橱窗信息 /// </summary> /// <param name="buf"></param> public void OnShopWindowInfoSync(KProtoBuf buf) { GetShopProxy().ClearShopWindow(); S2C_SYNC_SHOP_INFO msg = (S2C_SYNC_SHOP_INFO)buf; GetShopProxy().SetShopId(msg.shop_id); GetShopProxy().SetRefreshTime(msg.refresh_time); for (int i = 0; i < msg.goods_list.Count; i++) { GoodsInfo info = msg.goods_list[i]; ShopWindowVO shopWindowVO = new ShopWindowVO(); shopWindowVO.Oid = info.oid; shopWindowVO.Tid = (uint)info.item_id; shopWindowVO.IsOpen = info.is_open; shopWindowVO.ShopItemConfig = GetCfgEternityProxy().GetShopData((uint)info.goods_id, (uint)info.item_id); shopWindowVO.RefreshTime = info.refresh_time; shopWindowVO.ServerLeftNum = info.server_left_num; shopWindowVO.LimitCount = shopWindowVO.ShopItemConfig.Value.IndividualLimitNum; shopWindowVO.Order = info.order; GetShopProxy().AddShopWindowData(info.oid, shopWindowVO); } GameFacade.Instance.SendNotification(NotificationName.MSG_SHOP_CHANGE); }
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; } } }
/// <summary> /// 设置商品数据 /// </summary> /// <param name="shopWindowVO"></param> /// <param name="isSelect"></param> /// <param name="isList"></param> public void SetData(ShopWindowVO shopWindowVO, bool isSelect, bool isList = false) { Init(); Item m_Item = shopWindowVO.ShopItemConfig.Value.ItemGood.Value; m_ShopItemData = shopWindowVO.ShopItemConfig.Value; m_Quality.color = ColorUtil.GetColorByItemQuality(m_Item.Quality); if (isList) { UIUtil.SetIconImage(m_Icon, TableUtil.GetItemIconBundle(m_Item.Id), TableUtil.GetItemIconImage(m_Item.Id)); UIUtil.SetIconImage(m_Icon2, TableUtil.GetItemIconBundle(m_Item.Id), TableUtil.GetItemIconImage(m_Item.Id)); } else { UIUtil.SetIconImage(m_Icon, TableUtil.GetItemIconBundle(m_Item.Id), TableUtil.GetItemSquareIconImage(m_Item.Id)); UIUtil.SetIconImage(m_Icon2, TableUtil.GetItemIconBundle(m_Item.Id), TableUtil.GetItemSquareIconImage(m_Item.Id)); } m_Name.text = TableUtil.GetItemName(m_Item.Id); m_Level.text = TableUtil.ShowLevel(1); m_Bounds.text = m_ShopItemData.Bounds.ToString(); if (shopWindowVO.LimitCount == -1) { m_Available.gameObject.SetActive(false); } else { m_Available.gameObject.SetActive(true); m_Available.text = string.Format(TableUtil.GetLanguageString("shop_text_1012"), shopWindowVO.LimitCount); } if (shopWindowVO.LimitCount < m_ShopItemData.Bounds) { m_Available.color = Color.red; } else { m_Available.color = isSelect ? new Color(41f / 255f, 41f / 255f, 41f / 255f, 1) : Color.white; } UIUtil.SetIconImage(m_MoneyIcon, TableUtil.GetItemIconBundle((KNumMoneyType)m_ShopItemData.MoneyType), TableUtil.GetItemIconImage((KNumMoneyType)m_ShopItemData.MoneyType)); if (m_ShopItemData.DisCount == 1) { m_Discount.gameObject.SetActive(false); m_GoodPrice = m_ShopItemData.BuyCost; } else { m_Discount.gameObject.SetActive(true); m_Discount.text = m_ShopItemData.BuyCost.ToString(); m_GoodPrice = Mathf.CeilToInt(m_ShopItemData.BuyCost * m_ShopItemData.DisCount); } m_Price.text = m_GoodPrice.ToString(); if (MoneyeEnough()) { m_Price.color = new Color(30f / 255f, 170f / 255f, 33f / 255f, 1); } else { m_Price.color = Color.red; } if (shopWindowVO.ServerLeftNum == -1) { m_Stock.text = TableUtil.GetLanguageString("shop_text_1010"); } else if (shopWindowVO.ServerLeftNum == 0) { m_Stock.text = TableUtil.GetLanguageString("shop_text_1013"); } else { m_Stock.text = string.Format(TableUtil.GetLanguageString("shop_text_1011"), shopWindowVO.ServerLeftNum); } m_Stock.color = isSelect ? new Color(41f / 255f, 41f / 255f, 41f / 255f, 1) : Color.white; m_Black.gameObject.SetActive(shopWindowVO.IsOpen == 0); }