using asap.core; using EnhancedUI.EnhancedScroller; using GameCore; using TMPro; using UnityEngine; using UnityEngine.UI; using ScrollViewItemInfo = EventPartnerScrollViewItem.ScrollViewItemInfo; using EScrollViewType = EventPartnerScrollViewItem.EScrollViewType; namespace UI.PartnerGather.ScrollItems { public class EventPartnerGatherScrollViewItem : EnhancedScrollerCellView { public TMP_Text textName, textLvl, textBtnYes, textState, textTime; public Head avatar; public Button btnNo, btnYes; public GameObject iconLoadingGo, btnGrayGo, timeGo; private const string AcceptKey = "UI_EventPartnerFishbowlPanel_18", InviteKey = "UI_EventPartnerFishbowlPanel_17"; private ScrollViewItemInfo _info; public EScrollViewType Type => _info.Type; private bool _isNew = true; private void Start() { btnNo.onClick.AddListener(OnClickIgnore); btnYes.onClick.AddListener(OnClickYes); // GContext.OnEvent() // .Subscribe(_ => ActivateButton()) // .AddTo(this); } public void Init(ScrollViewItemInfo info) { ActivateButton(); if (info.Type == EScrollViewType.Title) { LogError("InitSkipped reason=TitleInfoInItemCell"); return; } _info = info; 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); } if (info.LastLoginTime.HasValue) textTime.text = ConvertTools.ConvertActiveTime(ZZTimeHelper.UtcNow() - info.LastLoginTime.Value); else { textTime.text = ""; // Debug.Log($"[EventPartner]Fail to get last login time."); } timeGo.SetActive(info.Type == EScrollViewType.Friend && textTime.text != ""); textState.gameObject.SetActive(info.Type == EScrollViewType.MyInvitation && info.IsFull); if (!_isNew) return; _isNew = false; } public async void OnClickYes() { // ELog("OnClickYes"); // Debug.Log($"[EventPartner]OnClickYes -> {_info.Type} {_info.PlayfabId} {_info.DisplayName}."); DeactivateButton(); await Awaiters.NextFrame; if (_info.Type == EScrollViewType.Partner2Accept) OnClickAccept(); else OnClickInvite(); } private void OnClickInvite() { GContext.Publish(new EventPartnerGatherClickInvite { Info = _info }); } private void OnClickAccept() { GContext.Publish(new EventPartnerGatherClickAccept { Info = _info }); } private void OnClickIgnore() { DeactivateButton(); GContext.Publish(new EventPartnerGatherClickIgnore { Info = _info }); } private void DeactivateButton() { // ELog("DeactivateButton"); btnYes.interactable = false; btnNo.interactable = false; } public void ActivateButton() { // ELog("ActivateButton"); btnYes.interactable = true; btnNo.interactable = true; } private static void LogError(string message) { Debug.LogError($"EventPartnerGatherScrollViewItem -> {message}"); } } public class EventPartnerGatherRemoveScrollViewItem { public ScrollViewItemInfo Info; } public class EventPartnerGatherClickAccept { public ScrollViewItemInfo Info; } public class EventPartnerGatherClickInvite { public ScrollViewItemInfo Info; } public class EventPartnerGatherClickIgnore { public ScrollViewItemInfo Info; } public class EventPartnerGatherUnlockScrollViewItemButton { } }