public void ApplyData(User data, bool enableAddFriend, bool enableInteraction) { if (data == null) { Clear(); return; } _data = data; _username = data.username; Nickname.SetData(data); var title = LevelTitle.TitleOf(data.level); title = string.IsNullOrEmpty(title) ? "" : title; if (!string.IsNullOrEmpty(title)) { title = string.Format("({0})", title); } else { title = ""; } Level.text = string.Format("{0}级{1}", data.level, title); Money.SetCurrency(data.money, CurrencyType.GOLDEN_EGG); // 将胜率改成显示场次。 // var rate = data.round_count > 0 ? (float)data.win_count/data.round_count : 0; var winCount = data.win_count; if (winCount < 0) { winCount = 0; } var loseCount = data.round_count - data.win_count; if (loseCount < 0) { loseCount = 0; } WinRate.text = string.Format("胜{0}场,败{1}场", winCount, loseCount); // Description.text = data.description; // 只有在需要添加好友并且检测是不是好友的情况下才显示添加好友按钮。 var friendListResult = _friendtListResult.Read(); var show = enableAddFriend && !GameUtil.IsFriend(friendListResult, _username); if (AddFriendBtn.gameObject.activeSelf != show) { AddFriendBtn.gameObject.SetActive(show); } InitInteraction(enableInteraction); }
/// <summary> /// 刷新source和target的显示数量。 /// </summary> private void UpdateSourceAndTargetValue() { var sourceType = _data != null ? _data.source_type : CurrencyType.YIN_PIAO; var sourceAmount = _data != null ? _data.source_amount : 0; var targetType = _data != null ? _data.target_type : CurrencyType.GOLDEN_EGG; var targetAmount = _data != null ? _data.target_amount : 0; SourceCount.SetCurrency(_exchangeCount * sourceAmount, sourceType); TargetCount.SetCurrency(_exchangeCount * targetAmount, targetType); }
public override void BindData(int currentIndex, RaceConfig data) { _data = data; if (data == null) { return; } // 载入比赛图片。 if (string.IsNullOrEmpty(data.pic)) { RaceIcon.Reset(); } else { RaceIcon.SetTargetPic(data.pic, null, data.pic_url); } DisPlayNameTxt.text = data.display_name; RaceDateTxt.text = data.race_description; RaceDescriptionTxt.text = data.award_description; RaceStartTimeTxt.text = data.open_time; if (data.fee != null) { Tickets.SetCurrency(data.fee.count, data.fee.type); } if (!data.race_over) { SignUpOverBtn.gameObject.SetActive(false); SignUpBtn.gameObject.SetActive(!data.signed_up); MatchBtn.gameObject.SetActive(data.signed_up); } else { SignUpOverBtn.gameObject.SetActive(true); } }
private void EnablePrice(bool enable, Currency currency = null) { if (!Price) { return; } if (Price.gameObject.activeSelf != enable) { Price.gameObject.SetActive(enable); } if (enable) { if (currency != null) { Price.SetCurrency(currency.count, currency.type); } else { Price.Clear(); } } }
private void SetDetailContent(Commodity data) { if (data != null) { var vip = data.vip_level > 0; if (VIPTag.activeSelf != vip) { VIPTag.SetActive(vip); } if (DetailImage && !DetailImage.gameObject.activeSelf) { DetailImage.gameObject.SetActive(true); } if (DetailBgImage && DetailBgImage.gameObject.activeSelf) { DetailBgImage.gameObject.SetActive(true); } var pic = data.pic; if (DetailImage) { if (!string.IsNullOrEmpty(pic)) { DetailImage.SetTargetPic(pic, ResourcePath.CommodityPath, null, true); } else { DetailImage.Reset(); } } if (DetailBgImage) { var picBg = data.pic_bg; if (!string.IsNullOrEmpty(picBg)) { DetailBgImage.SetTargetPic(picBg, ResourcePath.CommodityPath, null, true); } else { DetailBgImage.Reset(); } } if (DetailName) { if (!DetailName.gameObject.activeSelf) { DetailName.gameObject.SetActive(true); } DetailName.text = data.display_name; } if (DetailPrice) { if (!DetailPrice.gameObject.activeSelf) { DetailPrice.gameObject.SetActive(true); } DetailPrice.SetCurrency(CommodityHelper.GetPrice(data), CommodityHelper.GetCurrencyType(data)); } var bag = _bag.Read(); var user = _user.Read(); var hasCommodity = GameUtil.HasCommodity(bag, data); var equiped = hasCommodity && GameUtil.IsCommodityEquiped(bag, user, data); if (hasCommodity) { // 隐藏购买按钮。 if (BuyBtn && BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(false); } // 使用按钮与是否装备相反。 if (UseBtn) { if (!UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(true); } UseBtn.interactable = !equiped; } if (UnUseBtn) { if (!UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(true); } UnUseBtn.interactable = equiped; } // 6.2版本不再显示典当按钮。 if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } // 6.2版本不再显示典当提示。 if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } else { if (BuyBtn && !BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(true); } if (UseBtn && UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(false); } if (UnUseBtn && UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(false); } if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } } else { if (DetailBgImage) { DetailBgImage.Reset(); } if (DetailImage) { DetailImage.Reset(); } if (DetailName && DetailName.gameObject.activeSelf) { DetailName.gameObject.SetActive(false); } if (DetailPrice && DetailPrice.gameObject.activeSelf) { DetailPrice.gameObject.SetActive(false); } if (BuyBtn && BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(false); } if (UseBtn && UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(false); } if (UnUseBtn && UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(false); } if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } }
/// <summary> /// 应用玩家数据。 /// </summary> /// <param name="data"></param> public void ApplyData(User data) { if (data == null) { Data = null; // Close function group when clear data. ShowFuncGroup(false); ShowKickOutCounter(false); if (SelfIndicator && SelfIndicator.gameObject.activeSelf) { SelfIndicator.gameObject.SetActive(false); } if (ReadyIndicator && ReadyIndicator.gameObject.activeSelf) { ReadyIndicator.gameObject.SetActive(false); } if (Level) { Level.text = ""; } if (LevelTitle) { LevelTitle.text = ""; } if (WinRate) { WinRate.text = ""; } if (Money) { Money.Clear(); } if (Nickname) { Nickname.Clear(); } if (Player) { Player.Clear(); } } else { // 之前的数据是空,或者数据发生了变化,则关闭倒计时和功能按钮。 if (Data == null || !StringUtil.AreEqual(data.username, Data.username)) { // FIXME bug就出在这里了。 ShowFuncGroup(false); ShowKickOutCounter(false); } Data = data; var tableUser = _tableUserData.Read(); var self = tableUser.IsMySelf(data); if (SelfIndicator && SelfIndicator.gameObject.activeSelf != self) { SelfIndicator.gameObject.SetActive(self); } var ready = data.ready == 1; if (ReadyIndicator && ReadyIndicator.gameObject.activeSelf != ready) { ReadyIndicator.gameObject.SetActive(ready); } if (Level) { Level.text = "" + data.level; } if (LevelTitle) { LevelTitle.text = "" + data.title; } if (WinRate) { float rate = data.round_count != 0 ? ((float)data.win_count) / data.round_count : 0; WinRate.text = DataUtil.FormatWinRate(rate); } if (Money) { var room = _room.Read(); var currencyType = room == null ? CurrencyType.GOLDEN_EGG : room.currency_type; Money.SetCurrency(DataUtil.GetCurrency(data, currencyType), currencyType); } if (Nickname) { Nickname.SetData(data); } if (Player) { Player.ApplyData(data); } } }
public override void BindData(int currentIndex, Room data) { _data = data; if (data == null) { // 如果没有数据的话,应该怎么显示房间按钮呢? // 房间可以不显示,但是是不是要显示在线人数。 return; } // 载入人数和底注。 BaseMoney.SetCurrency(_data.base_money, CurrencyType.GOLDEN_EGG); PlayerCount.text = "" + data.current_player_num; // 载入房间图片。 if (string.IsNullOrEmpty(data.room_pic)) { RoomPic.Reset(); } else { var resourcePath = GetAssetBundleByPicNameMap.GetAssetBundleName(data.room_pic); RoomPic.SetTargetPic(data.room_pic, resourcePath, data.room_pic_url); } if (data.type == RoomType.Ad) { RoomContainer.SetActive(false); TagContainer.SetActive(false); var hintItem = data.hint_item; if (hintItem != null && !string.IsNullOrEmpty(hintItem.content_pic)) { var contentPic = _resourceCache.LoadSpriteFromLocalFile(hintItem.content_pic); if (!contentPic) { if (!string.IsNullOrEmpty(hintItem.content_pic_url) && !_resourceCache.ContainsDownloadTask(hintItem.content_pic)) { _resourceCache.StartDownload( hintItem.content_pic, hintItem.content_pic_url, ContentType.Image); } } } } else { RoomContainer.SetActive(true); TagContainer.SetActive(true); } // 设置标签。 if (!string.IsNullOrEmpty(data.tag)) { if (!Tag1Group.activeSelf) { Tag1Group.SetActive(true); } Tag1.text = data.tag; } else { if (Tag1Group.activeSelf) { Tag1Group.SetActive(false); } } if (!string.IsNullOrEmpty(data.tag1)) { if (!Tag2Group.activeSelf) { Tag2Group.SetActive(true); } Tag2.text = data.tag1; } else { if (Tag2Group.activeSelf) { Tag2Group.SetActive(false); } } if (!Button.gameObject.activeSelf) { Button.gameObject.SetActive(true); } }