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 ...@@ -235,26 +235,42 @@ namespace MDPro3.Servant
private IEnumerator RefreshMyCardAssets() 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(); var task = MyCard.GetExp();
while (!task.IsCompleted) while (!task.IsCompleted)
yield return null; 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) while (!Appearance.loaded)
yield return null; yield return null;
GetUI<OnlineServantUI>().PageMyCard.UserProfile.Avatar.material = Appearance.duelFrameMat0; if (userProfile.Avatar != null)
userProfile.Avatar.material = Appearance.duelFrameMat0;
if (MyCard.avatar == null) if (MyCard.avatar == null)
{ {
var avatarTask = Tools.DownloadImageAsync(MyCard.account.user.avatar); var avatarAddress = MyCard.account?.user?.avatar;
while (!avatarTask.IsCompleted) if (!string.IsNullOrEmpty(avatarAddress))
yield return null; {
MyCard.avatar = avatarTask.Result; var avatarTask = Tools.DownloadImageAsync(avatarAddress);
GetUI<OnlineServantUI>().PageMyCard.UserProfile.Avatar.texture = MyCard.avatar; 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() private void RefreshDeckSelector()
......
...@@ -111,22 +111,58 @@ namespace MDPro3.UI ...@@ -111,22 +111,58 @@ namespace MDPro3.UI
public void SetProfile(MyCardUserExp data) public void SetProfile(MyCardUserExp data)
{ {
TextUserName.text = MyCard.account.user.name; if (data == null)
return;
TextExpValue.text = data.exp.ToString();
TextDPValue.text = data.pt.ToString(); var userInfo = MyCard.account?.user;
TextAthleticWinValue.text = data.athletic_win.ToString(); var userName = userInfo?.name;
TextAthleticWinRatioValue.text = data.athletic_wl_ratio + "%"; if (string.IsNullOrEmpty(userName))
TextAthleticRankValue.text = data.arena_rank.ToString(); userName = userInfo?.username ?? string.Empty;
TextEntertainCountValue.text = data.entertain_all.ToString();
TextEntertainRankValue.text = data.exp_rank.ToString(); var textUserName = TextUserName;
if (textUserName != null)
var rankSprites = TextureManager.container.GetRankSprites(data.pt); textUserName.text = userName;
IconBG.sprite = rankSprites[0]; var textExpValue = TextExpValue;
IconRank.sprite = rankSprites[1]; if (textExpValue != null)
IconTier1.sprite = rankSprites[2]; textExpValue.text = data.exp.ToString();
IconTier2.sprite = rankSprites[3]; var textDPValue = TextDPValue;
IconTier3.sprite = rankSprites[4]; 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