94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using cfg;
|
|
using asap.core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Assertions;
|
|
using TMPro;
|
|
using GameCore;
|
|
using System.Linq;
|
|
|
|
public class EventLuckMagicBlockView : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject[] goBackgrounds;
|
|
// [SerializeField] private RewardItemNew reward;
|
|
[SerializeField] private Image icon, iconNum;
|
|
[SerializeField] private GameObject goReceived, goUpperTaskIcon, goLowerTaskIcon, goOuterRingSign, goMiddleRingSign;
|
|
[SerializeField] private CardLogoNum iconCard;
|
|
[SerializeField] private TMP_Text textNum;
|
|
[SerializeField] private Button button;
|
|
|
|
|
|
public void Init(EventLuckMagicBlock data)
|
|
{
|
|
button.onClick.RemoveAllListeners();
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
GContext.container.Resolve<PlayerItemData>().ShowItemTips(data.Reward.id, button.transform);
|
|
});
|
|
for (int i = 0; i < goBackgrounds.Length; i++)
|
|
{
|
|
goBackgrounds[i].SetActive((int)data.BlockType == i);
|
|
}
|
|
HideAllIcons();
|
|
goReceived.SetActive(data.IsTaken);
|
|
var res = GContext.container.Resolve<Tables>().TbItem.DataMap.TryGetValue(data.Reward.id, out var item);
|
|
Assert.IsTrue(res, $"Item {data.Reward.id} not found in item list.");
|
|
var count = data.Reward.count;
|
|
if (item.Type == 5)
|
|
{
|
|
iconCard.gameObject.SetActive(true);
|
|
iconCard.Init(item);
|
|
return;
|
|
}
|
|
var itemType = EventLuckMagicAct.TableContext.JudgeItemId(data.Reward.id);
|
|
switch (itemType)
|
|
{
|
|
case EEventLuckMagicItemType.UpperTaskItem:
|
|
goUpperTaskIcon.SetActive(true);
|
|
return;
|
|
case EEventLuckMagicItemType.LowerTaskItem:
|
|
goLowerTaskIcon.SetActive(true);
|
|
return;
|
|
default:
|
|
break;
|
|
}
|
|
if (data.BlockType == EEventLuckMagicBlockType.RoadSign)
|
|
{
|
|
goOuterRingSign.SetActive(data.ParentRing.RingType == EEventLuckMagicRingType.OuterRing);
|
|
goMiddleRingSign.SetActive(data.ParentRing.RingType == EEventLuckMagicRingType.MiddleRing);
|
|
return;
|
|
}
|
|
if (count == 1f)
|
|
{
|
|
icon.gameObject.SetActive(true);
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, item.Icon);
|
|
}
|
|
else
|
|
{
|
|
iconNum.gameObject.SetActive(true);
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(iconNum, item.Icon);
|
|
textNum.text = FtMathUtils.GetNumberString(count);
|
|
}
|
|
}
|
|
|
|
public void SetReceived(bool isReceived = true)
|
|
{
|
|
// if (EventLuckMagicAct.TableContext.IsRewardRoadSign(reward.id, out _, out _))
|
|
// goReceived.SetActive(false);
|
|
// else
|
|
goReceived.SetActive(isReceived);
|
|
}
|
|
|
|
private void HideAllIcons()
|
|
{
|
|
icon.gameObject.SetActive(false);
|
|
iconNum.gameObject.SetActive(false);
|
|
iconCard.gameObject.SetActive(false);
|
|
goUpperTaskIcon.SetActive(false);
|
|
goLowerTaskIcon.SetActive(false);
|
|
goOuterRingSign.SetActive(false);
|
|
goMiddleRingSign.SetActive(false);
|
|
goReceived.SetActive(false);
|
|
}
|
|
}
|