GigPopup.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using DataTools;
  2. using System;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class GigPopup : GameNotification
  6. {
  7. [Header("DATAUSER")]
  8. [SerializeField] private DataUser dataUser;
  9. [SerializeField] private Text glamText;
  10. [SerializeField] private Text dollarsText;
  11. [SerializeField] private Text experienceText;
  12. [SerializeField] private Image starsImage;
  13. private DataTools.Currency gigReward;
  14. private float starsEarnedPercent;
  15. public delegate void OnUIClose();
  16. public static event OnUIClose OnClose;
  17. public DataTools.Currency Open(DataTools.Gig newGig)
  18. {
  19. starsEarnedPercent = ((float)dataUser.UserData.StarsEarned / (float)newGig.StarsNeeded);
  20. dataUser.UserData.StarsEarned = 0;
  21. gigReward = new DataTools.Currency(GetRewardValue(newGig.Currency.Glam),
  22. GetRewardValue(newGig.Currency.Experience),
  23. GetRewardValue(newGig.Currency.Dollars),
  24. 0,
  25. newGig.Currency.Level);
  26. SetupUI(newGig.Id);
  27. RegisterNotification();
  28. return gigReward;
  29. }
  30. private void SetupUI(string id)
  31. {
  32. glamText.transform.parent.gameObject.SetActive(gigReward.Glam != 0);
  33. glamText.text = gigReward.Glam.ToString();
  34. dollarsText.transform.parent.gameObject.SetActive(gigReward.Dollars != 0);
  35. dollarsText.text = gigReward.Dollars.ToString();
  36. experienceText.transform.parent.gameObject.SetActive(gigReward.Experience != 0);
  37. experienceText.text = gigReward.Experience.ToString();
  38. starsImage.fillAmount = starsEarnedPercent;
  39. }
  40. public int GetRewardValue(int value)
  41. {
  42. return (int) Mathf.Ceil(value * starsEarnedPercent);
  43. }
  44. public void Close()
  45. {
  46. if (dataUser.UserData.ProgressData != null)
  47. {
  48. dataUser.UserData.CurrencyData.AddReward(gigReward.Glam,
  49. gigReward.Experience,
  50. gigReward.Dollars,
  51. gigReward.Motivation);
  52. }
  53. gameObject.SetActive(false);
  54. if (OnClose != null)
  55. {
  56. OnClose();
  57. }
  58. }
  59. }