123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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 <Gig_Timer>)";
- string timer_holder2 = "<Gig_Timer>";
- 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<PanelCurrenciesBehaviour>();
- 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 <Gig_Timer>)";
- string timer_holder2 = "<Gig_Timer>";
- 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);
- }
- }
- }
|