using asap.core; using cfg; using DG.Tweening; using game; using GameCore; using System; using TMPro; using UniRx; using UnityEngine; using UnityEngine.UI; public class DialogueEnergyHelp : DialogueBase { ClubService clubService; public Button btn_donate; public Button btn_donate_gray; public GameObject done; public TMP_Text text_progress; public Image bar; public Animation ani; long cursorId; int count; int ClubLureRequestCount = 5; int ClubLureDonateLimit = 50; string content; bool hasHelped; Tables tables; bool isEnable = true; protected override void Awake() { tables = GContext.container.Resolve(); ClubLureRequestCount = tables.TbGlobalConfig.ClubLureRequestCount; ClubLureDonateLimit = tables.TbGlobalConfig.ClubLureDonateLimit; base.Awake(); clubService = GContext.container.Resolve(); btn_donate.onClick.AddListener(OnClickDonate); btn_donate_gray.onClick.AddListener(OnClickDonate); } async void OnClickDonate() { if (playFabId == userService.UserId) { ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_68")); InitHelpState(); return; } if (hasHelped) { ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_67")); return; } if (clubService.ClubLureDonateCount >= ClubLureDonateLimit) { return; } btn_donate.gameObject.SetActive(false); hasHelped = true; //捐赠成功 count++; SetHelpState(count); AddProgress(); content = await clubService.SendHelpOthersEnergy(playFabId, cursorId); if (!string.IsNullOrEmpty(content)) { hasHelped = content.Contains(userService.UserId); count = content.Split("#").Length; } ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_69")); } async void AddProgress() { if (count > ClubLureRequestCount) { count = ClubLureRequestCount; } text_progress.text = $"{count}/{ClubLureRequestCount}"; bar.DOFillAmount((float)count / ClubLureRequestCount, 0.5f); if (count >= ClubLureRequestCount) { await Awaiters.Seconds(0.5f); ani.Play(); } } public void Init(string userID, long cursorId, string message, DateTime timeSpan, bool isSame) { isSame = false; playFabId = userID; this.cursorId = cursorId; done.gameObject.SetActive(false); btn_donate_gray.gameObject.SetActive(false); btn_donate.gameObject.SetActive(false); hasHelped = true; text_progress.text = $"{0}/{ClubLureRequestCount}"; bar.fillAmount = 0; InitHelpState(); Init(timeSpan, isSame); } async void InitHelpState() { content = await clubService.GetHelpEnergyState(cursorId); if (!isEnable) { return; } if (!string.IsNullOrEmpty(content)) { hasHelped = content.Contains(userService.UserId); count = content.Split("#").Length; } else { hasHelped = false; } if (count > ClubLureRequestCount) { count = ClubLureRequestCount; } SetHelpState(count); text_progress.text = $"{count}/{ClubLureRequestCount}"; bar.fillAmount = (float)count / ClubLureRequestCount; } void SetHelpState(int curCount) { if (curCount < ClubLureRequestCount) { bool isGray = playFabId == userService.UserId || hasHelped || clubService.ClubLureDonateCount >= ClubLureDonateLimit; btn_donate_gray.gameObject.SetActive(isGray); btn_donate.gameObject.SetActive(!isGray); done.gameObject.SetActive(false); } else { btn_donate_gray.gameObject.SetActive(false); btn_donate.gameObject.SetActive(false); done.gameObject.SetActive(true); } } private void OnDestroy() { isEnable = false; } }