SanAndreasUnity/Assets/Scripts/UI/DayTimeWindow.cs

98 lines
2.5 KiB
C#
Raw Normal View History

2020-05-31 17:07:22 +00:00
using System.Collections.Generic;
using UnityEngine;
using SanAndreasUnity.Behaviours.World;
namespace SanAndreasUnity.UI {
public class DayTimeWindow : PauseMenuWindow {
2021-05-02 21:01:31 +00:00
public byte[] availableHours = {7, 12, 15, 18, 21, 0, 3};
2021-05-02 23:54:26 +00:00
private string m_hoursText = "12";
private string m_minutesText = "0";
private string m_timeScaleText = "1";
2020-05-31 17:07:22 +00:00
DayTimeWindow() {
// set default parameters
this.windowName = "DayTime";
}
void Start () {
this.RegisterButtonInPauseMenu ();
// adjust rect
2021-05-04 19:28:47 +00:00
this.windowRect = new Rect(Screen.width * 0.7f, 10, 250, 300);
2020-05-31 17:07:22 +00:00
}
protected override void OnWindowGUI ()
{
2021-05-03 00:00:55 +00:00
if (null == DayTimeManager.Singleton)
{
GUILayout.Label($"{nameof(DayTimeManager)} not available");
return;
}
2020-05-31 17:07:22 +00:00
2021-05-02 23:59:33 +00:00
GUILayout.Label($"Current time: {DayTimeManager.Singleton.CurrentTimeHours}:{DayTimeManager.Singleton.CurrentTimeMinutes}");
GUILayout.Label($"Time scale: {DayTimeManager.Singleton.timeScale}");
2021-05-02 21:01:31 +00:00
GUILayout.Space(15);
2020-05-31 17:07:22 +00:00
GUILayout.Label("Set Time:");
2021-05-02 21:01:31 +00:00
GUILayout.BeginHorizontal();
foreach (byte hour in this.availableHours)
{
if (GUILayout.Button(hour.ToString()))
2021-05-02 23:59:33 +00:00
DayTimeManager.Singleton.SetTime(hour, 0, true);
2021-05-02 21:01:31 +00:00
}
GUILayout.EndHorizontal();
GUILayout.Space(15);
GUILayout.BeginHorizontal();
GUILayout.Label("Hours:");
m_hoursText = GUILayout.TextField(m_hoursText);
GUILayout.Label("Minutes:");
m_minutesText = GUILayout.TextField(m_minutesText);
GUILayout.EndHorizontal();
2021-05-02 23:54:26 +00:00
if (GUILayout.Button("Set time"))
2020-05-31 17:07:22 +00:00
{
2021-05-02 21:01:31 +00:00
if (byte.TryParse(m_hoursText, out byte hours) && byte.TryParse(m_minutesText, out byte minutes))
{
2021-05-02 23:59:33 +00:00
DayTimeManager.Singleton.SetTime(hours, minutes, true);
2021-05-02 21:01:31 +00:00
}
2020-05-31 17:07:22 +00:00
}
2021-05-02 23:54:26 +00:00
GUILayout.BeginHorizontal();
if (GUILayout.Button("Previous hour"))
2021-05-02 23:59:33 +00:00
DayTimeManager.Singleton.SetTime((byte) (DayTimeManager.Singleton.CurrentTimeHours == 0 ? 23 : DayTimeManager.Singleton.CurrentTimeHours - 1), DayTimeManager.Singleton.CurrentTimeMinutes, true);
2021-05-02 23:54:26 +00:00
if (GUILayout.Button("Next hour"))
2021-05-02 23:59:33 +00:00
DayTimeManager.Singleton.SetTime((byte) ((DayTimeManager.Singleton.CurrentTimeHours + 1) % 24), DayTimeManager.Singleton.CurrentTimeMinutes, true);
2021-05-02 23:54:26 +00:00
GUILayout.EndHorizontal();
GUILayout.Space(15);
GUILayout.BeginHorizontal();
GUILayout.Label("Time scale:");
m_timeScaleText = GUILayout.TextField(m_timeScaleText);
if (GUILayout.Button("Set scale"))
{
if (float.TryParse(m_timeScaleText, out float value))
2021-05-02 23:59:33 +00:00
DayTimeManager.Singleton.timeScale = value;
2021-05-02 23:54:26 +00:00
}
GUILayout.EndHorizontal();
2020-05-31 17:07:22 +00:00
}
}
}