126 lines
4.1 KiB
C#
126 lines
4.1 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingSocialFriendSearchPanel : MonoBehaviour
|
|
{
|
|
Button btn_close;
|
|
TMP_InputField InputField_name;
|
|
Button btn_search;
|
|
GameObject btn_searchgo;
|
|
GameObject btn_search_graygo;
|
|
|
|
FishingSocialFriendAddPanel fishingSocialFriendAddPanel;
|
|
private void Awake()
|
|
{
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
InputField_name = transform.Find("root/InputField_name").GetComponent<TMP_InputField>();
|
|
InputField_name.onValueChanged.AddListener(OnInputFieldValueChanged);
|
|
btn_search = transform.Find("root/btn_search/btn_green").GetComponent<Button>();
|
|
//
|
|
btn_searchgo = transform.Find("root/btn_search").gameObject;
|
|
btn_search_graygo = transform.Find("root/btn_search_gray").gameObject;
|
|
fishingSocialFriendAddPanel = transform.Find("FishingSocialFriendAddPanel").GetComponent<FishingSocialFriendAddPanel>();
|
|
}
|
|
void Start()
|
|
{
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_search.onClick.AddListener(OnBtnSearchClick);
|
|
}
|
|
|
|
|
|
private string GetPlayFabIDByInvitationCode(string invitationCode)
|
|
{
|
|
ulong code = GContext.container.Resolve<FriendService>().DecryptInvitationCodeToUlong(invitationCode);
|
|
return code.ToString("X");
|
|
}
|
|
|
|
bool m_IsSearching = false;
|
|
private async void OnBtnSearchClick()
|
|
{
|
|
if (m_IsSearching == true) return;
|
|
|
|
string invitationCode = InputField_name.text;
|
|
if (string.IsNullOrEmpty(invitationCode))
|
|
{
|
|
m_IsSearching = false;
|
|
return;
|
|
}
|
|
|
|
invitationCode = invitationCode.ToUpperInvariant();
|
|
invitationCode = invitationCode.Replace("-", "");
|
|
string playFabID = GetPlayFabIDByInvitationCode(invitationCode);
|
|
if (playFabID == GContext.container.Resolve<IUserService>().UserId)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_100"));
|
|
return;
|
|
}
|
|
m_IsSearching = true;
|
|
btn_search_graygo.SetActive(true);
|
|
btn_searchgo.SetActive(false);
|
|
string json = await GContext.container.Resolve<FriendService>().SearchFriend(playFabID);
|
|
|
|
if (!string.IsNullOrEmpty(json))
|
|
{
|
|
try
|
|
{
|
|
SearchFriendResp searchFriendResp = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchFriendResp>(json);
|
|
if (searchFriendResp.Code > 0)
|
|
{
|
|
BFriendInfo FriendInfo = searchFriendResp.Info;
|
|
fishingSocialFriendAddPanel.gameObject.SetActive(true);
|
|
await fishingSocialFriendAddPanel.SetBFriendInfo(FriendInfo);
|
|
}
|
|
else
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_101"));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
GameDebug.LogError("FishingFriendAddPanel deserialize [SearchFriendResp] data has failed. Exception: " + ex.ToString());
|
|
}
|
|
}
|
|
m_IsSearching = false;
|
|
btn_search_graygo.SetActive(false);
|
|
btn_searchgo.SetActive(true);
|
|
}
|
|
|
|
|
|
|
|
void OnInputFieldValueChanged(string input)
|
|
{
|
|
string cleanedInput = input.Replace("-", "");
|
|
|
|
string formattedInput = FormatWithDashes(cleanedInput);
|
|
|
|
formattedInput = formattedInput.ToUpperInvariant();
|
|
|
|
InputField_name.text = formattedInput;
|
|
|
|
int caretPositoin = formattedInput.Length;
|
|
|
|
InputField_name.caretPosition = caretPositoin;
|
|
InputField_name.selectionStringAnchorPosition = caretPositoin;
|
|
InputField_name.selectionStringFocusPosition = caretPositoin;
|
|
}
|
|
|
|
string FormatWithDashes(string input)
|
|
{
|
|
for (int i = 3; i < input.Length; i += 4)
|
|
{
|
|
input = input.Insert(i, "-");
|
|
}
|
|
return input;
|
|
}
|
|
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.HideUI(UITypes.FishingSocialFriendSearchPanel);
|
|
}
|
|
}
|