51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using Assets.Scripts.Interfaces;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class TopPanel : MonoBehaviour
|
|
{
|
|
private Label _timeLabel;
|
|
private Label _moneyLabel;
|
|
private Label _locationLabel;
|
|
private VisualElement _energy;
|
|
private VisualElement _food;
|
|
|
|
void Start()
|
|
{
|
|
GameManager.Instance.Time.OnMinuteChanged -= UpdateTime;
|
|
GameManager.Instance.Time.OnMinuteChanged += UpdateTime;
|
|
|
|
var root = GetComponent<UIDocument>().rootVisualElement;
|
|
_timeLabel = root.Q<Label>("TimeLabel");
|
|
_locationLabel= root.Q<Label>("LocationLabel");
|
|
_moneyLabel = root.Q<Label>("MoneyLabel");
|
|
|
|
_energy = root.Q<VisualElement>("EnergyProgressFill");
|
|
_food = root.Q<VisualElement>("HungerProgressFill");
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
GameManager.Instance.Time.OnMinuteChanged -= UpdateTime;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
_moneyLabel.text = $"${(Player.Instance.Stats[StatsId.Money] as INumericStat).Value}";
|
|
_locationLabel.text= $"{(Player.Instance.Stats[StatsId.LocationName] as IStringStat).Value}";
|
|
}
|
|
|
|
private void UpdateTime()
|
|
{
|
|
if (_timeLabel != null)
|
|
{
|
|
_timeLabel.text = $"{GameManager.Instance.Time.CurrentTime.GetDayName()} {GameManager.Instance.Time.CurrentTime.ToString(@"hh\:mm")} day ({GameManager.Instance.Time.CurrentTime.Days})";
|
|
}
|
|
|
|
//progressBarFill.style.width = new Length(progress * 100, LengthUnit.Percent);
|
|
_energy.style.width = new Length((Player.Instance.Stats[StatsId.Energy] as INumericStat).Value , LengthUnit.Percent);
|
|
_food.style.width = new Length((Player.Instance.Stats[StatsId.Food] as INumericStat).Value, LengthUnit.Percent);
|
|
}
|
|
}
|