103 lines
2.8 KiB
C#
103 lines
2.8 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PromptedLike : MonoBehaviour
|
|
{
|
|
public TMP_Text text_prompted;
|
|
public Button btn_like;
|
|
public GameObject icon;
|
|
public GameObject icon_done;
|
|
public TMP_Text text_num;
|
|
|
|
IUserService userService;
|
|
string playFabId;
|
|
IDisposable disposable;
|
|
string multilingual;
|
|
string mapName;
|
|
ClubService clubService;
|
|
long cursorId;
|
|
int num;
|
|
bool isEnable = true;
|
|
private void Awake()
|
|
{
|
|
userService = GContext.container.Resolve<IUserService>();
|
|
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
|
|
}
|
|
private void Start()
|
|
{
|
|
icon.SetActive(true);
|
|
icon_done.SetActive(false);
|
|
btn_like.onClick.AddListener(() =>
|
|
{
|
|
SetBtnState(true);
|
|
num++;
|
|
text_num.text = num.ToString();
|
|
clubService.SendLike(cursorId);
|
|
});
|
|
}
|
|
void SetBtnState(bool like)
|
|
{
|
|
btn_like.enabled = !like;
|
|
icon.SetActive(!like);
|
|
icon_done.SetActive(like);
|
|
}
|
|
public void Init(long cursorId, string message, ClubService clubService)
|
|
{
|
|
btn_like.enabled = false;
|
|
this.cursorId = cursorId;
|
|
string[] str = message.Split('_');
|
|
playFabId = str[0];
|
|
int mapIndex = int.Parse(str[1]);
|
|
var data = GContext.container.Resolve<Tables>().TbMapData.DataList[mapIndex];
|
|
mapName = $"{mapIndex + 1}.{LocalizationMgr.GetText(data.Name_l10n_key)}";
|
|
|
|
multilingual = LocalizationMgr.GetText("UI_FishingSocialPanel_25");
|
|
if (playFabId == userService.UserId)
|
|
{
|
|
text_prompted.text = multilingual.SafeFormat(userService.DisplayName, mapName);
|
|
}
|
|
else
|
|
{
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
|
if (clubPlayInfo != null)
|
|
{
|
|
text_prompted.text = multilingual.SafeFormat(clubPlayInfo.name, mapName);
|
|
}
|
|
}
|
|
this.clubService = clubService;
|
|
//点赞
|
|
SetLike();
|
|
}
|
|
async void SetLike()
|
|
{
|
|
(bool islike, int likeNum) = await clubService.GetLikeCount(cursorId);
|
|
if (!isEnable)
|
|
{
|
|
return;
|
|
}
|
|
num = likeNum;
|
|
text_num.text = likeNum.ToString();
|
|
SetBtnState(islike);
|
|
}
|
|
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
|
|
{
|
|
if (getClubPlayInfoEvent.id == playFabId)
|
|
{
|
|
text_prompted.text = multilingual.SafeFormat(getClubPlayInfoEvent.name, mapName);
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
isEnable = false;
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
}
|