ChallengeRequestItem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using TMPro;
  5. using ICTS.Localization;
  6. public class ChallengeRequestItem : MonoBehaviour
  7. {
  8. public TextMeshProUGUI label;
  9. public RawImage avatar;
  10. ChallengeRequestUIData _challengeRequestData;
  11. public void SetData(RequestInfo challengeRequestInfo)
  12. {
  13. _challengeRequestData = new ChallengeRequestUIData(challengeRequestInfo);
  14. label.text = string.Format(Localization.instance.Get("challengeRequests.requestText"), _challengeRequestData.name, _challengeRequestData.score, _challengeRequestData.levelId + 1);
  15. SocialManager.Instance.GetFacebookProfilePicture(challengeRequestInfo.senderID, SocialManager.ProfilePicSettings.square, (isSuccessful, texture) =>
  16. {
  17. avatar.texture = texture;
  18. });
  19. }
  20. void OnDeclineButtonMsg()
  21. {
  22. //UIUtils.EnableWidgets(gameObject, false);
  23. FacebookHelper.Instance.DeclineChallenge(_challengeRequestData, (isSuccessful) => {
  24. if (!isSuccessful)
  25. {
  26. //re-enable for retrying
  27. //UIUtils.EnableWidgets(gameObject, true);
  28. }
  29. });
  30. }
  31. void OnAcceptButtonMsg()
  32. {
  33. if (LivesManager.Instance.CanPlay)
  34. {
  35. #if UNITY_EDITOR
  36. NotificationCenter.Post(NotificationType.SelectNextLevel, 0);
  37. #else
  38. FacebookHelper.Instance.AcceptChallenge(_challengeRequestData);
  39. #endif
  40. } else
  41. {
  42. NotificationCenter.Post(NotificationType.TriedPlayingWithoutLivesLeft);
  43. }
  44. }
  45. }