118 lines
3.0 KiB
C#
118 lines
3.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using DG.Tweening;
|
|
|
|
public class rewardSlotPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public Image borderIconImg;
|
|
public Sprite[] borderIconSprites;
|
|
public Image rewardIcon;
|
|
public Text rewardName;
|
|
public Text rewardAmount;
|
|
|
|
public GameObject detailBtm;
|
|
public Text detailText;
|
|
|
|
void OnEnable()
|
|
{
|
|
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)
|
|
{
|
|
return;
|
|
}
|
|
|
|
detailBtm.SetActive(true);
|
|
UI_OrderedEntryAnimator.PlayFadeOnly(detailBtm, 0, 0.12f, 0f, true);
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (detailBtm == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
CanvasGroup group = detailBtm.GetComponent<CanvasGroup>();
|
|
if (group == null)
|
|
{
|
|
group = detailBtm.AddComponent<CanvasGroup>();
|
|
}
|
|
|
|
group.DOKill();
|
|
group.DOFade(0f, 0.1f)
|
|
.SetEase(Ease.OutQuad)
|
|
.SetUpdate(true)
|
|
.SetTarget(detailBtm)
|
|
.OnComplete(() =>
|
|
{
|
|
if (detailBtm != null)
|
|
{
|
|
detailBtm.SetActive(false);
|
|
group.alpha = 1f;
|
|
}
|
|
});
|
|
}
|
|
}
|