133 lines
4.1 KiB
C#
133 lines
4.1 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class DialogueHelp : DialogueBase
|
|
{
|
|
ClubService clubService;
|
|
public Button btn_donate;
|
|
public Button btn_donate_gray;
|
|
public GameObject done;
|
|
public TMP_Text text_donor;
|
|
public TMP_Text text_photo_name;
|
|
public TMP_Text text_help;
|
|
long cursorId;
|
|
int count = 0;
|
|
int pictureID;
|
|
string curDonateId;
|
|
IDisposable disposable;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
clubService = GContext.container.Resolve<ClubService>();
|
|
//btn_donate.onClick.AddListener(OnClickDonate);
|
|
//btn_donate_gray.onClick.AddListener(OnClickDonate);
|
|
}
|
|
async void OnClickDonate()
|
|
{
|
|
if (playFabId == userService.UserId)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_35"));
|
|
return;
|
|
}
|
|
count = GContext.container.Resolve<AlbumData>().GetPictureProgress(pictureID);
|
|
if (count <= 1)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_34"));
|
|
}
|
|
else
|
|
{
|
|
btn_donate.gameObject.SetActive(false);
|
|
//捐赠成功
|
|
var donateId = await clubService.SendDonatePhoto(playFabId, cursorId, pictureID);
|
|
|
|
if (string.IsNullOrEmpty(donateId))
|
|
{
|
|
donateId = userService.UserId;
|
|
}
|
|
SetPhotoState(donateId);
|
|
}
|
|
}
|
|
public void Init(string userID, long cursorId, string message, DateTime timeSpan, bool isSame)
|
|
{
|
|
playFabId = userID;
|
|
this.cursorId = cursorId;
|
|
var picture = GContext.container.Resolve<Tables>().TbPicture.GetOrDefault(int.Parse(message));
|
|
done.gameObject.SetActive(false);
|
|
if (picture != null)
|
|
{
|
|
btn_donate_gray.gameObject.SetActive(false);
|
|
btn_donate.gameObject.SetActive(false);
|
|
pictureID = picture.ID;
|
|
count = GContext.container.Resolve<AlbumData>().GetPictureProgress(picture.ID);
|
|
InitPhotoState();
|
|
text_photo_name.text = LocalizationMgr.GetText(picture.Title_l10n_key);
|
|
}
|
|
else
|
|
{
|
|
btn_donate_gray.gameObject.SetActive(true);
|
|
btn_donate.gameObject.SetActive(false);
|
|
}
|
|
Init(timeSpan, isSame);
|
|
}
|
|
async void InitPhotoState()
|
|
{
|
|
var donateId = await clubService.GetPhotoState(playFabId, cursorId);
|
|
SetPhotoState(donateId);
|
|
}
|
|
void SetPhotoState(string donateId)
|
|
{
|
|
if (string.IsNullOrEmpty(donateId))
|
|
{
|
|
curDonateId = "";
|
|
//未捐赠
|
|
//btn_donate_gray.gameObject.SetActive(count <= 1);
|
|
//btn_donate.gameObject.SetActive(count > 1);
|
|
btn_donate_gray.gameObject.SetActive(true);
|
|
btn_donate.gameObject.SetActive(false);
|
|
done.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//已捐赠
|
|
btn_donate.gameObject.SetActive(false);
|
|
btn_donate_gray.gameObject.SetActive(false);
|
|
done.gameObject.SetActive(true);
|
|
//展示捐赠人名称和对勾
|
|
//donateId
|
|
curDonateId = donateId;
|
|
if (userService.UserId == curDonateId)
|
|
{
|
|
text_donor.text = userService.DisplayName;
|
|
}
|
|
else
|
|
{
|
|
if (disposable == null)
|
|
{
|
|
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == curDonateId).Subscribe(SetAvatar);
|
|
}
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(curDonateId);
|
|
if (clubPlayInfo != null)
|
|
{
|
|
text_donor.text = clubPlayInfo.name;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
|
|
{
|
|
if (getClubPlayInfoEvent.id == curDonateId)
|
|
{
|
|
text_donor.text = getClubPlayInfoEvent.name;
|
|
}
|
|
}
|
|
}
|