using DataTools; using UnityEngine; using UnityEngine.UI; using WebTools.Currencies.Behaviours; public class PanelSkipBehaviour : MonoBehaviour { [SerializeField] private DataGame dataGame; [SerializeField] private DataUser dataUser; [SerializeField] private Text description; [SerializeField] private Text costValue; [SerializeField] private GameObject background; private int glamCost = 1; private PanelCurrenciesBehaviour panelCurrencies; private static PanelSkipBehaviour instance; public bool Visible { get { return background.activeSelf; } } private void Start() { Debug.Log("PanelSkip Start"); Init(); //gameObject.SetActive(false); this.Activate(false); } public void Activate(bool flag) { if(flag) { if(instance == null) Init(); background.SetActive(true); int taskIndex = dataUser.UserData.ProgressData.Quest; DataTools.Quest quest = dataGame.GameData.GetQuestById(dataUser.UserData.ProgressData.QuestId); string taskDescr = (quest != null) ? quest.Description : "Current project"; string timer_holder = "(available in )"; string timer_holder2 = ""; if(taskDescr.Contains(timer_holder)) taskDescr = taskDescr.Replace(timer_holder, ""); if(taskDescr.Contains(timer_holder2)) taskDescr = taskDescr.Replace(timer_holder2, ""); if(description != null) description.text = taskDescr; if(GameplayManager.instance != null) { float currentTaskDuration = (float)GameplayManager.instance.CurrentTaskDuration; float secInHour = 3600.0f; glamCost = (int)Mathf.Ceil(currentTaskDuration / secInHour); } if(costValue != null) costValue.text = glamCost.ToString(); if(glamCost < 0 || glamCost == 0) this.Activate(false); } else { background.SetActive(false); } } public static PanelSkipBehaviour Instance { get { return instance; } } private void Init() { panelCurrencies = FindObjectOfType(); instance = this; } private void OnEnable() { return; Debug.Log("PanelSkip OnEnable"); if (instance == null) Init(); int taskIndex = dataUser.UserData.ProgressData.Quest; DataTools.Quest quest = dataGame.GameData.GetQuestById(dataUser.UserData.ProgressData.QuestId); string taskDescr = (quest != null) ? quest.Description : "Current project";//(quest != null && taskIndex < quest.Tasks.Count) ? quest.Tasks[taskIndex].Description : "Current task"; string timer_holder = "(available in )"; string timer_holder2 = ""; if (taskDescr.Contains(timer_holder)) taskDescr = taskDescr.Replace(timer_holder, ""); if (taskDescr.Contains(timer_holder2)) taskDescr = taskDescr.Replace(timer_holder2, ""); if (description != null) description.text = taskDescr; if(GameplayManager.instance!=null) { float currentTaskDuration = (float)GameplayManager.instance.CurrentTaskDuration; float secInHour = 3600.0f; glamCost = (int)Mathf.Ceil(currentTaskDuration / secInHour); } if (costValue != null) costValue.text = glamCost.ToString(); if (glamCost < 0 || glamCost == 0) this.gameObject.SetActive(false); } public void OnStartNowClick() { int playersGlam = dataUser.UserData.CurrencyData.Glam; if(playersGlam < glamCost) { panelCurrencies.ShowPanelNotGlam((glamCost - playersGlam).ToString(), "Glam"); } else { GameplayManager.instance.SkipCurrentWaitingTime(); dataUser.UserData.CurrencyData.Glam -= glamCost; background.SetActive(false); } } }