ChallengeRequestItem.cs 1.3 KB

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