Files
back_cantanBuilding/Assets/Scripts/UI/PartnerFishBowl/EventPartnerScrollViewItem.cs
2026-05-26 16:15:54 +08:00

139 lines
4.6 KiB
C#

using System;
using EnhancedUI.EnhancedScroller;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using GameCore;
public class EventPartnerScrollViewItem : EnhancedScrollerCellView
{
public TMP_Text textName, textLvl, textBtnYes, textState, textTime;
public Head avatar;
public Button btnNo, btnYes;
public GameObject iconLoadingGo, btnGrayGo, timeGo;
private string _playfabId;
private const string AcceptKey = "UI_EventPartnerFishbowlPanel_18", InviteKey = "UI_EventPartnerFishbowlPanel_17";
private ScrollViewItemInfo _info;
private bool _isNew = true;
public void Init(ScrollViewItemInfo info)
{
if (info.Type == EScrollViewType.Title)
{
Debug.Log( "<color=red>[EventPartner] An item scrollViewCell is initiated with title info.</color>");
return;
}
_info = info;
_playfabId = info.PlayfabId;
textName.text = info.DisplayName;
avatar.SetData(info.AvatarUrl);
textLvl.text = info.Level.ToString();
btnNo.transform.parent.gameObject.SetActive(info.Type != EScrollViewType.Friend && info.Type != EScrollViewType.MyInvitation);
textBtnYes.text = LocalizationMgr.GetText(info.Type == EScrollViewType.Partner2Accept ? AcceptKey : InviteKey);
if (info.Type == EScrollViewType.MyInvitation)
{
btnYes.transform.parent.gameObject.SetActive(false);
btnGrayGo.SetActive(true);
}
else //(info.Type == EScrollViewType.Partner2Accept)
{
btnYes.transform.parent.gameObject.SetActive(true);
btnGrayGo.SetActive(false);
}
// btnYes.gameObject.SetActive(info.Type == EScrollViewType.Partner2Accept || !info.IsInvitationPending);
// Debug.Log($"<color=#c191ff>[EventPartner]{info.DisplayName}: {info.Type != EScrollViewType.Partner2Accept && info.IsInvitationPending}</color>");
// btnGrayGo.SetActive(info.Type != EScrollViewType.Partner2Accept && info.IsInvitationPending);
if (info.LastLoginTime.HasValue)
textTime.text = ConvertTools.ConvertActiveTime(ZZTimeHelper.UtcNow() - info.LastLoginTime.Value);
else
{
textTime.text = "";
Debug.Log($"<color=#c191ff>[EventPartner]Fail to get last login time.</color>");
}
timeGo.SetActive(info.Type == EScrollViewType.Friend && textTime.text != "");
textState.gameObject.SetActive(info.Type == EScrollViewType.MyInvitation && info.IsFull);
if (!_isNew)
return;
_isNew = false;
btnNo.onClick.AddListener(OnClickIgnore);
btnYes.onClick.AddListener(info.Type == EScrollViewType.Partner2Accept ? OnClickAccept : OnClickInvite);
}
private void OnClickInvite()
{
EventPartnerAct.Ctx.EventAggregator.Publish(new EventPartnerClickInvite { Info = _info });
}
private void OnClickAccept()
{
EventPartnerAct.Ctx.EventAggregator.Publish(new EventPartnerClickAccept { Info = _info });
}
private void OnClickIgnore()
{
EventPartnerAct.Ctx.EventAggregator.Publish(new EventPartnerClickIgnore { Info = _info });
}
public class ScrollViewItemInfo : IEquatable<ScrollViewItemInfo>
{
public EScrollViewType Type;
public string PlayfabId;
public string AvatarUrl;
public string DisplayName;
public int Level;
public bool IsFull = false;
public string Title;
public DateTime? LastLoginTime;
#region EQ override
public bool Equals(ScrollViewItemInfo other)
{
return Type == other.Type && PlayfabId == other.PlayfabId && Title == other.Title;
}
public override bool Equals(object obj)
{
return obj is ScrollViewItemInfo other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine((int)Type, PlayfabId, AvatarUrl, DisplayName, Level,
Title, LastLoginTime);
}
#endregion
}
public enum EScrollViewType
{
Title,
Recommendation,
Friend,
Partner2Accept,
MyInvitation
}
}
public class EventPartnerRemoveScrollViewItem
{
public EventPartnerScrollViewItem.ScrollViewItemInfo Info;
}
public class EventPartnerClickAccept
{
public EventPartnerScrollViewItem.ScrollViewItemInfo Info;
}
public class EventPartnerClickInvite
{
public EventPartnerScrollViewItem.ScrollViewItemInfo Info;
}
public class EventPartnerClickIgnore
{
public EventPartnerScrollViewItem.ScrollViewItemInfo Info;
}