255 lines
8.8 KiB
C#
255 lines
8.8 KiB
C#
using asap.core;
|
||
using GameCore;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.UI;
|
||
|
||
namespace game
|
||
{
|
||
public class FriendRecommendedItem : FriendAddItem
|
||
{
|
||
TMP_Text text_name;
|
||
Head btn_head;
|
||
TMP_Text text_num;
|
||
GameObject btn_invite_root;
|
||
Button btn_invite;
|
||
GameObject btn_invite_icon_loading;
|
||
GameObject btn_invite_p_text;
|
||
GameObject btn_invite_gray_root;
|
||
Button btn_invite_gray;
|
||
Button btn_skip;
|
||
|
||
#region 数据相关
|
||
public override void SetData(FishingFriendAddPanel panel, FriendAddItemData data, UnityAction<FriendAddItemData> callback)
|
||
{
|
||
m_Panel = panel;
|
||
if (data == null || data.FriendInfo == null) return;
|
||
BFriendInfo bFriendInfo = data.FriendInfo;
|
||
|
||
base.SetData(panel, data, callback);
|
||
|
||
InitUI();
|
||
|
||
ResumeScale();
|
||
|
||
EnableBtn();
|
||
|
||
if (string.IsNullOrEmpty(bFriendInfo.DisplayName))
|
||
{
|
||
bFriendInfo.DisplayName = GContext.container.Resolve<game.IUserService>().GetDefaultName(bFriendInfo.PlayFabId);
|
||
}
|
||
|
||
text_name.text = bFriendInfo.DisplayName;
|
||
|
||
btn_head.SetData(bFriendInfo.AvatarUrl);
|
||
text_num.text = "" + bFriendInfo.Level;
|
||
|
||
if (data.Extra == 1)
|
||
{
|
||
btn_skip.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
btn_skip.gameObject.SetActive(true);
|
||
}
|
||
|
||
string userID = GContext.container.Resolve<IUserService>().UserId;
|
||
if (userID.Equals(bFriendInfo.PlayFabId) || GContext.container.Resolve<FriendService>().IsFriend(bFriendInfo.PlayFabId))
|
||
{
|
||
btn_invite_root.SetActive(false);
|
||
btn_invite_gray_root.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
btn_invite_root.SetActive(true);
|
||
btn_invite_gray_root.SetActive(false);
|
||
}
|
||
|
||
m_IsSkipping = false;
|
||
m_IsInviting = false;
|
||
}
|
||
#endregion
|
||
|
||
#region UI
|
||
bool m_IsSkipping = false;
|
||
private void OnBtnInviteGrayClickListener()
|
||
{
|
||
if (m_Data == null) return;
|
||
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_94"));
|
||
}
|
||
private void OnBtnSkipClick()
|
||
{
|
||
if (m_Data == null) return;
|
||
|
||
DisableBtn();
|
||
LockScrollView();
|
||
|
||
StartScalingAnimation(() =>
|
||
{
|
||
//if (Callback != null)
|
||
//{
|
||
// Callback(m_Data);
|
||
//}
|
||
if (m_Panel != null)
|
||
{
|
||
m_Panel.RemoveRecommendedData(m_Data);
|
||
}
|
||
EnableBtn();
|
||
});
|
||
|
||
//if (m_IsSkipping == true) return;
|
||
//m_IsSkipping = true;
|
||
//if (Callback != null)
|
||
//{
|
||
// Callback(m_Data);
|
||
//}
|
||
//m_IsSkipping = false;
|
||
}
|
||
|
||
bool m_IsInviting = false;
|
||
private void OnBtnInviteClick()
|
||
{
|
||
if (m_Data == null) return;
|
||
|
||
DisableBtn();
|
||
LockScrollView();
|
||
|
||
StartScalingAnimation(() =>
|
||
{
|
||
//if (Callback != null)
|
||
//{
|
||
// Callback(m_Data);
|
||
//}
|
||
if (m_Panel != null)
|
||
{
|
||
m_Panel.StartRecommendedInvite(m_Data);
|
||
}
|
||
EnableBtn();
|
||
});
|
||
|
||
// if (m_IsInviting == true) return;
|
||
|
||
// m_IsInviting = true;
|
||
// if (btn_invite_p_text != null)
|
||
// {
|
||
// btn_invite_p_text.SetActive(false);
|
||
// }
|
||
// if (btn_invite_icon_loading != null)
|
||
// {
|
||
// btn_invite_icon_loading.SetActive(true);
|
||
// }
|
||
// string json = await GContext.container.Resolve<FriendService>().AddFriend(m_Data.FriendInfo.PlayFabId);
|
||
|
||
// if (!string.IsNullOrEmpty(json))
|
||
// {
|
||
// // code 1:添加好友成功;-1:我的好友已满;-2:对方好友已满;-3:获取对方好友列表失败;-4:我加对方好友失败;-5:对方加我好友失败;2:已经添加过对方好友;
|
||
// AddFriendResp addFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<AddFriendResp>(json);
|
||
// if (addFriendResp != null)
|
||
// {
|
||
//#if AGG
|
||
// using (var e = GEvent.GameEvent("friend_send"))
|
||
// {
|
||
// e.AddContent("playfabid", GContext.container.Resolve<IUserService>().UserId)
|
||
// .AddContent("friendplayfabid", m_Data.FriendInfo.PlayFabId)
|
||
// .AddContent("code", addFriendResp.Code)
|
||
// .AddContent("friendcode", GContext.container.Resolve<FriendService>().GetInvitationCodeByPlayFabID(m_Data.FriendInfo.PlayFabId));
|
||
// }
|
||
//#endif
|
||
|
||
// switch (addFriendResp.Code)
|
||
// {
|
||
// case FriendHelper.Code_OK:
|
||
// case FriendHelper.Code_AddFriend_HaveAddedBefore_OK:
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_90"));
|
||
// if (Callback != null)
|
||
// {
|
||
// Callback(m_Data);
|
||
// }
|
||
// break;
|
||
// case FriendHelper.Code_AddFriend_FriendHaveNoLimit:
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_91"));
|
||
// break;
|
||
// case FriendHelper.Code_AddFriend_IHaveNoLimit:
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_92"));
|
||
// break;
|
||
// case FriendHelper.Code_AddFriend_GetFriendList_Failed_PlayFabError:
|
||
// case FriendHelper.Code_AddFriend_IAddFriend_Failed_PlayFabError:
|
||
// case FriendHelper.Code_AddFriend_FriendAddMe_Failed_PlayFabError:
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
// break;
|
||
// default:
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_93"));
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// if (btn_invite_icon_loading != null)
|
||
// {
|
||
// btn_invite_icon_loading.SetActive(false);
|
||
// }
|
||
// if (btn_invite_p_text != null)
|
||
// {
|
||
// btn_invite_p_text.SetActive(true);
|
||
// }
|
||
// m_IsInviting = false;
|
||
}
|
||
|
||
bool m_IsInit = false;
|
||
private void InitUI()
|
||
{
|
||
if (m_IsInit == true) return;
|
||
|
||
RectTransform rectTransform = transform.GetComponent<RectTransform>();
|
||
originalScale = rectTransform.localScale;
|
||
|
||
text_name = transform.Find("text_name").GetComponent<TMP_Text>();
|
||
btn_head = transform.Find("btn_head").GetComponent<Head>();
|
||
text_num = transform.Find("icon_rank/icon/text_num").GetComponent<TMP_Text>();
|
||
|
||
btn_invite_root = transform.Find("btn_invite").gameObject;
|
||
btn_invite = transform.Find("btn_invite/btn_green_c").GetComponent<Button>();
|
||
btn_invite_icon_loading = transform.Find("btn_invite/btn_green_c/Ani_Container/icon_loading").gameObject;
|
||
btn_invite_p_text = transform.Find("btn_invite/btn_green_c/Ani_Container/p_text").gameObject;
|
||
btn_invite.onClick.AddListener(OnBtnInviteClick);
|
||
|
||
btn_invite_gray_root = transform.Find("btn_invite_gray").gameObject;
|
||
btn_invite_gray = transform.Find("btn_invite_gray/btn_green_c").GetComponent<Button>();
|
||
btn_invite_gray.onClick.AddListener(OnBtnInviteGrayClickListener);
|
||
btn_invite_gray_root.SetActive(false);
|
||
|
||
btn_skip = transform.Find("btn_skip/btn_green_c").GetComponent<Button>();
|
||
btn_skip.onClick.AddListener(OnBtnSkipClick);
|
||
|
||
m_IsInit = true;
|
||
}
|
||
private void DisableBtn()
|
||
{
|
||
if (btn_invite != null)
|
||
{
|
||
btn_invite.enabled = false;
|
||
}
|
||
if (btn_skip != null)
|
||
{
|
||
btn_skip.enabled = false;
|
||
}
|
||
}
|
||
private void EnableBtn()
|
||
{
|
||
if (btn_invite != null)
|
||
{
|
||
btn_invite.enabled = true;
|
||
}
|
||
if (btn_skip != null)
|
||
{
|
||
btn_skip.enabled = true;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|