SanAndreasUnity/Assets/Scripts/UI/DayTimeWindow.cs

72 lines
1.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};
private string m_hoursText = "";
private string m_minutesText = "";
2020-05-31 17:07:22 +00:00
DayTimeWindow() {
// set default parameters
this.windowName = "DayTime";
}
void Start () {
this.RegisterButtonInPauseMenu ();
// adjust rect
this.windowRect = new Rect(10, Screen.height - 220, 250, 200);
}
protected override void OnWindowGUI ()
{
2021-05-02 21:01:31 +00:00
GUILayout.Label($"Current time: {WorldController.Singleton.CurrentTimeHours}:{WorldController.Singleton.CurrentTimeMinutes}");
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()))
WorldController.Singleton.SetTime(hour, 0, true);
}
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();
if (GUILayout.Button("Set"))
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))
{
WorldController.Singleton.SetTime(hours, minutes, true);
}
2020-05-31 17:07:22 +00:00
}
}
}
}