little refactor
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TimeSliderUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _description;
|
||||
[SerializeField]
|
||||
private Button _btnCancel;
|
||||
[SerializeField]
|
||||
private Button _btnOk;
|
||||
[SerializeField]
|
||||
private Slider _slider;
|
||||
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
TimeManager.Instance.OnFastForwardEnd += CloseDialog;
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||
TimeManager.Instance.Pause();
|
||||
UIManager.Instance.Freeze();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
_description.text = description;
|
||||
_btnCancel.onClick.AddListener(() =>
|
||||
{
|
||||
onCancel?.Invoke();
|
||||
Hide();
|
||||
CloseDialog();
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke(TimeSpan.FromSeconds(_slider.value));
|
||||
Hide();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
UIManager.Instance.Unfreeze();
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = TimeSpan.FromSeconds(_slider.value);
|
||||
|
||||
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
TimeManager.Instance.Resume();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 108151baa6db03042b0bcf80b1a30a66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TopBarUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _timeText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _moneyText;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _energy;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _food;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
TimeManager.Instance.OnMinuteChanged -= UpdateTime;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_moneyText.text = $"${Player.Instance.Stats[StatsId.Money].Value}";
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
if (_timeText != null)
|
||||
{
|
||||
_timeText.text = TimeManager.CurrentTime.ToString(@"hh\:mm");
|
||||
}
|
||||
|
||||
_energy.value = (float)Player.Instance.Stats[StatsId.Energy].Value;
|
||||
_food.value = (float)Player.Instance.Stats[StatsId.Food].Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2649ed9748ff3864880311f1c2aecdef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public TimeSliderUI _timeSliderPrefab;
|
||||
[SerializeField]
|
||||
public GameObject _blurOverlay;
|
||||
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_blurOverlay.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
var timeSlider = Instantiate(_timeSliderPrefab, transform);
|
||||
timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void Freeze()
|
||||
{
|
||||
_blurOverlay.SetActive(true);
|
||||
}
|
||||
|
||||
public void Unfreeze()
|
||||
{
|
||||
_blurOverlay.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 152bb7481f494844aa5ddb27a421f8b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user