UI update 02
This commit is contained in:
@@ -4,6 +4,8 @@ using UnityEngine.EventSystems;
|
||||
|
||||
public class rewardSlotPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Image borderIconImg;
|
||||
public Sprite[] borderIconSprites;
|
||||
public Image rewardIcon;
|
||||
public Text rewardName;
|
||||
public Text rewardAmount;
|
||||
@@ -16,6 +18,63 @@ public class rewardSlotPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExi
|
||||
if (detailBtm != null) detailBtm.SetActive(false);
|
||||
}
|
||||
|
||||
public void BindReward(mail_so.rewardItem reward)
|
||||
{
|
||||
if (reward == null)
|
||||
{
|
||||
ApplyBorderSprite(ItemRarity.None);
|
||||
return;
|
||||
}
|
||||
|
||||
MailRewardGrantService.PopulateRewardDisplay(reward);
|
||||
|
||||
if (rewardName != null) rewardName.text = reward.rewardName;
|
||||
if (rewardAmount != null) rewardAmount.text = reward.reward_ammount == 1 ? string.Empty : reward.reward_ammount.ToString();
|
||||
if (rewardIcon != null) rewardIcon.sprite = reward.reward_image;
|
||||
if (detailText != null) detailText.text = reward.reward_description;
|
||||
|
||||
if (!MailRewardGrantService.TryGetRewardRarity(reward, out ItemRarity rarity))
|
||||
{
|
||||
rarity = ItemRarity.None;
|
||||
}
|
||||
ApplyBorderSprite(rarity);
|
||||
}
|
||||
|
||||
private void ApplyBorderSprite(ItemRarity rarity)
|
||||
{
|
||||
if (borderIconImg == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = ResolveBorderSprite(rarity);
|
||||
borderIconImg.sprite = sprite;
|
||||
borderIconImg.enabled = sprite != null;
|
||||
}
|
||||
|
||||
private Sprite ResolveBorderSprite(ItemRarity rarity)
|
||||
{
|
||||
if (borderIconSprites != null && borderIconSprites.Length > 0)
|
||||
{
|
||||
int enumIndex = (int)rarity;
|
||||
if (enumIndex >= 0 && enumIndex < borderIconSprites.Length)
|
||||
{
|
||||
Sprite sprite = borderIconSprites[enumIndex];
|
||||
if (sprite != null)
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
|
||||
if (borderIconSprites[0] != null)
|
||||
{
|
||||
return borderIconSprites[0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (detailBtm != null) detailBtm.SetActive(true);
|
||||
|
||||
Reference in New Issue
Block a user