12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using DataTools;
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- public class GigPopup : GameNotification
- {
- [Header("DATAUSER")]
- [SerializeField] private DataUser dataUser;
- [SerializeField] private Text glamText;
- [SerializeField] private Text dollarsText;
- [SerializeField] private Text experienceText;
- [SerializeField] private Image starsImage;
- private DataTools.Currency gigReward;
- private float starsEarnedPercent;
- public delegate void OnUIClose();
- public static event OnUIClose OnClose;
- public DataTools.Currency Open(DataTools.Gig newGig)
- {
- starsEarnedPercent = ((float)dataUser.UserData.StarsEarned / (float)newGig.StarsNeeded);
- dataUser.UserData.StarsEarned = 0;
- gigReward = new DataTools.Currency(GetRewardValue(newGig.Currency.Glam),
- GetRewardValue(newGig.Currency.Experience),
- GetRewardValue(newGig.Currency.Dollars),
- 0,
- newGig.Currency.Level);
- SetupUI(newGig.Id);
- RegisterNotification();
- return gigReward;
- }
- private void SetupUI(string id)
- {
- glamText.transform.parent.gameObject.SetActive(gigReward.Glam != 0);
- glamText.text = gigReward.Glam.ToString();
- dollarsText.transform.parent.gameObject.SetActive(gigReward.Dollars != 0);
- dollarsText.text = gigReward.Dollars.ToString();
- experienceText.transform.parent.gameObject.SetActive(gigReward.Experience != 0);
- experienceText.text = gigReward.Experience.ToString();
- starsImage.fillAmount = starsEarnedPercent;
- }
- public int GetRewardValue(int value)
- {
- return (int) Mathf.Ceil(value * starsEarnedPercent);
- }
- public void Close()
- {
- if (dataUser.UserData.ProgressData != null)
- {
- dataUser.UserData.CurrencyData.AddReward(gigReward.Glam,
- gigReward.Experience,
- gigReward.Dollars,
- gigReward.Motivation);
- }
- gameObject.SetActive(false);
- if (OnClose != null)
- {
- OnClose();
- }
- }
- }
|