PanelSkipBehaviour.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using DataTools;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using WebTools.Currencies.Behaviours;
  5. public class PanelSkipBehaviour : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private DataGame dataGame;
  9. [SerializeField]
  10. private DataUser dataUser;
  11. [SerializeField]
  12. private Text description;
  13. [SerializeField]
  14. private Text costValue;
  15. [SerializeField]
  16. private GameObject background;
  17. private int glamCost = 1;
  18. private PanelCurrenciesBehaviour panelCurrencies;
  19. private static PanelSkipBehaviour instance;
  20. public bool Visible { get { return background.activeSelf; } }
  21. private void Start()
  22. {
  23. Debug.Log("PanelSkip Start");
  24. Init();
  25. //gameObject.SetActive(false);
  26. this.Activate(false);
  27. }
  28. public void Activate(bool flag)
  29. {
  30. if(flag)
  31. {
  32. if(instance == null)
  33. Init();
  34. background.SetActive(true);
  35. int taskIndex = dataUser.UserData.ProgressData.Quest;
  36. DataTools.Quest quest = dataGame.GameData.GetQuestById(dataUser.UserData.ProgressData.QuestId);
  37. string taskDescr = (quest != null) ? quest.Description : "Current project";
  38. string timer_holder = "(available in <Gig_Timer>)";
  39. string timer_holder2 = "<Gig_Timer>";
  40. if(taskDescr.Contains(timer_holder))
  41. taskDescr = taskDescr.Replace(timer_holder, "");
  42. if(taskDescr.Contains(timer_holder2))
  43. taskDescr = taskDescr.Replace(timer_holder2, "");
  44. if(description != null)
  45. description.text = taskDescr;
  46. if(GameplayManager.instance != null)
  47. {
  48. float currentTaskDuration = (float)GameplayManager.instance.CurrentTaskDuration;
  49. float secInHour = 3600.0f;
  50. glamCost = (int)Mathf.Ceil(currentTaskDuration / secInHour);
  51. }
  52. if(costValue != null)
  53. costValue.text = glamCost.ToString();
  54. if(glamCost < 0 || glamCost == 0)
  55. this.Activate(false);
  56. }
  57. else
  58. {
  59. background.SetActive(false);
  60. }
  61. }
  62. public static PanelSkipBehaviour Instance
  63. {
  64. get { return instance; }
  65. }
  66. private void Init()
  67. {
  68. panelCurrencies = FindObjectOfType<PanelCurrenciesBehaviour>();
  69. instance = this;
  70. }
  71. private void OnEnable()
  72. {
  73. return;
  74. Debug.Log("PanelSkip OnEnable");
  75. if (instance == null)
  76. Init();
  77. int taskIndex = dataUser.UserData.ProgressData.Quest;
  78. DataTools.Quest quest = dataGame.GameData.GetQuestById(dataUser.UserData.ProgressData.QuestId);
  79. string taskDescr = (quest != null) ? quest.Description : "Current project";//(quest != null && taskIndex < quest.Tasks.Count) ? quest.Tasks[taskIndex].Description : "Current task";
  80. string timer_holder = "(available in <Gig_Timer>)";
  81. string timer_holder2 = "<Gig_Timer>";
  82. if (taskDescr.Contains(timer_holder))
  83. taskDescr = taskDescr.Replace(timer_holder, "");
  84. if (taskDescr.Contains(timer_holder2))
  85. taskDescr = taskDescr.Replace(timer_holder2, "");
  86. if (description != null)
  87. description.text = taskDescr;
  88. if(GameplayManager.instance!=null)
  89. {
  90. float currentTaskDuration = (float)GameplayManager.instance.CurrentTaskDuration;
  91. float secInHour = 3600.0f;
  92. glamCost = (int)Mathf.Ceil(currentTaskDuration / secInHour);
  93. }
  94. if (costValue != null)
  95. costValue.text = glamCost.ToString();
  96. if (glamCost < 0 || glamCost == 0)
  97. this.gameObject.SetActive(false);
  98. }
  99. public void OnStartNowClick()
  100. {
  101. int playersGlam = dataUser.UserData.CurrencyData.Glam;
  102. if(playersGlam < glamCost)
  103. {
  104. panelCurrencies.ShowPanelNotGlam((glamCost - playersGlam).ToString(), "Glam");
  105. }
  106. else
  107. {
  108. GameplayManager.instance.SkipCurrentWaitingTime();
  109. dataUser.UserData.CurrencyData.Glam -= glamCost;
  110. background.SetActive(false);
  111. }
  112. }
  113. }