Commit 7149f95d authored by ElderLich's avatar ElderLich

Bug Fix: MyCard UserProfile null crash and rank sprite compile error

Added safe null checks in online profile refresh (OnlineServant/UserProfile) so missing MyCard data no longer crashes, and fixed rankSprites.Length to rankSprites.Count because rank sprites are a List<Sprite>.
parent 39b66e4b
......@@ -235,26 +235,42 @@ namespace MDPro3.Servant
private IEnumerator RefreshMyCardAssets()
{
var onlineUI = GetUI<OnlineServantUI>();
if (onlineUI == null || onlineUI.PageMyCard == null || onlineUI.PageMyCard.UserProfile == null)
yield break;
var userProfile = onlineUI.PageMyCard.UserProfile;
var task = MyCard.GetExp();
while (!task.IsCompleted)
yield return null;
GetUI<OnlineServantUI>().PageMyCard.UserProfile.SetProfile(task.Result);
MyCardUserExp expData = null;
if (!task.IsCanceled && task.Exception == null)
expData = task.Result;
userProfile.SetProfile(expData);
while (!Appearance.loaded)
yield return null;
GetUI<OnlineServantUI>().PageMyCard.UserProfile.Avatar.material = Appearance.duelFrameMat0;
if (userProfile.Avatar != null)
userProfile.Avatar.material = Appearance.duelFrameMat0;
if (MyCard.avatar == null)
{
var avatarTask = Tools.DownloadImageAsync(MyCard.account.user.avatar);
while (!avatarTask.IsCompleted)
yield return null;
MyCard.avatar = avatarTask.Result;
GetUI<OnlineServantUI>().PageMyCard.UserProfile.Avatar.texture = MyCard.avatar;
var avatarAddress = MyCard.account?.user?.avatar;
if (!string.IsNullOrEmpty(avatarAddress))
{
var avatarTask = Tools.DownloadImageAsync(avatarAddress);
while (!avatarTask.IsCompleted)
yield return null;
MyCard.avatar = avatarTask.Result;
}
}
GetUI<OnlineServantUI>().PageMyCard.ActivePageFunction();
if (userProfile.Avatar != null && MyCard.avatar != null)
userProfile.Avatar.texture = MyCard.avatar;
onlineUI.PageMyCard.ActivePageFunction();
}
private void RefreshDeckSelector()
......
......@@ -111,22 +111,58 @@ namespace MDPro3.UI
public void SetProfile(MyCardUserExp data)
{
TextUserName.text = MyCard.account.user.name;
TextExpValue.text = data.exp.ToString();
TextDPValue.text = data.pt.ToString();
TextAthleticWinValue.text = data.athletic_win.ToString();
TextAthleticWinRatioValue.text = data.athletic_wl_ratio + "%";
TextAthleticRankValue.text = data.arena_rank.ToString();
TextEntertainCountValue.text = data.entertain_all.ToString();
TextEntertainRankValue.text = data.exp_rank.ToString();
var rankSprites = TextureManager.container.GetRankSprites(data.pt);
IconBG.sprite = rankSprites[0];
IconRank.sprite = rankSprites[1];
IconTier1.sprite = rankSprites[2];
IconTier2.sprite = rankSprites[3];
IconTier3.sprite = rankSprites[4];
if (data == null)
return;
var userInfo = MyCard.account?.user;
var userName = userInfo?.name;
if (string.IsNullOrEmpty(userName))
userName = userInfo?.username ?? string.Empty;
var textUserName = TextUserName;
if (textUserName != null)
textUserName.text = userName;
var textExpValue = TextExpValue;
if (textExpValue != null)
textExpValue.text = data.exp.ToString();
var textDPValue = TextDPValue;
if (textDPValue != null)
textDPValue.text = data.pt.ToString();
var textAthleticWinValue = TextAthleticWinValue;
if (textAthleticWinValue != null)
textAthleticWinValue.text = data.athletic_win.ToString();
var textAthleticWinRatioValue = TextAthleticWinRatioValue;
if (textAthleticWinRatioValue != null)
textAthleticWinRatioValue.text = data.athletic_wl_ratio + "%";
var textAthleticRankValue = TextAthleticRankValue;
if (textAthleticRankValue != null)
textAthleticRankValue.text = data.arena_rank.ToString();
var textEntertainCountValue = TextEntertainCountValue;
if (textEntertainCountValue != null)
textEntertainCountValue.text = data.entertain_all.ToString();
var textEntertainRankValue = TextEntertainRankValue;
if (textEntertainRankValue != null)
textEntertainRankValue.text = data.exp_rank.ToString();
var rankSprites = TextureManager.container?.GetRankSprites(data.pt);
if (rankSprites == null || rankSprites.Count < 5)
return;
var iconBG = IconBG;
if (iconBG != null)
iconBG.sprite = rankSprites[0];
var iconRank = IconRank;
if (iconRank != null)
iconRank.sprite = rankSprites[1];
var iconTier1 = IconTier1;
if (iconTier1 != null)
iconTier1.sprite = rankSprites[2];
var iconTier2 = IconTier2;
if (iconTier2 != null)
iconTier2.sprite = rankSprites[3];
var iconTier3 = IconTier3;
if (iconTier3 != null)
iconTier3.sprite = rankSprites[4];
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment