Files
JJBB/Assets/Project/Script/GUI/SwornBrother/DaySelectRoot.cs

195 lines
4.7 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Games.GlobeDefine;
using GCGame.Table;
using GCGame;
public class DaySelectRoot : UIControllerBase<DaySelectRoot>
{
void OnEnable()
{
SetInstance(this);
}
void OnDisable()
{
SetInstance(null);
}
#region static
public static void ShowDaySelect(DaySelectedCallBack callBack)
{
Hashtable hash = new Hashtable();
hash.Add("CallBack", callBack);
UIManager.ShowUI(UIInfo.DaySelectRoot, OnDaySelectShow, hash);
}
static void OnDaySelectShow(bool bSuccess, object param)
{
Hashtable hash = param as Hashtable;
if (!bSuccess)
{
return;
}
if (hash == null)
{
return;
}
if (DaySelectRoot.Instance() != null)
{
DaySelectRoot.Instance().Show((DaySelectedCallBack)hash["CallBack"]);
}
}
#endregion
#region
public Text _YearTx;
public UIContainerSelect _YearContainer;
public Text _MonthTx;
public UIContainerSelect _MonthContainer;
public Text _DayTx;
public UIContainerSelect _DayContainer;
public delegate void DaySelectedCallBack(System.DateTime dateTime);
private DaySelectedCallBack _DaySelectedCallBack;
private int _SelectYear;
private int _SelectMonth;
private int _SelectDay;
public void Show(DaySelectedCallBack callBack)
{
_DaySelectedCallBack = callBack;
_YearContainer.gameObject.SetActive(false);
_MonthContainer.gameObject.SetActive(false);
_DayContainer.gameObject.SetActive(false);
var nowTime = System.DateTime.Now;
_SelectYear = nowTime.Year - 18;
_SelectMonth = 1;
_SelectDay = 1;
_YearTx.text = _SelectYear.ToString();
_MonthTx.text = _SelectMonth.ToString();
_DayTx.text = _SelectDay.ToString();
}
public void OnYearClick()
{
_YearContainer.gameObject.SetActive(true);
var nowTime = System.DateTime.Now;
if (_YearContainer.GetItemCount() == 0)
{
List<int> yearList = new List<int>();
for (int i = 1900; i <= nowTime.Year; ++i)
{
yearList.Add(i);
}
_YearContainer.InitSelectContent(yearList, new List<int>() { _SelectYear }, YearSelected);
}
else
{
_YearContainer.SetSelect(new List<int>() { _SelectYear });
}
}
private void YearSelected(object selectGO)
{
int year = (int)selectGO;
_YearTx.text = year.ToString();
if (_SelectYear != year)
{
_YearContainer.gameObject.SetActive(false);
}
_SelectYear = year;
}
public void OnMonthClick()
{
_MonthContainer.gameObject.SetActive(true);
if (_MonthContainer.GetItemCount() == 0)
{
List<int> monthList = new List<int>();
for (int i = 1; i <= 12; ++i)
{
monthList.Add(i);
}
_MonthContainer.InitSelectContent(monthList, new List<int>() { _SelectMonth }, MonthSelected);
}
else
{
_MonthContainer.SetSelect(new List<int>() { _SelectMonth });
}
}
private void MonthSelected(object selectGO)
{
int month = (int)selectGO;
_MonthTx.text = month.ToString();
if (_SelectMonth != month)
{
_MonthContainer.gameObject.SetActive(false);
}
_SelectMonth = month;
}
public void OnDayClick()
{
_DayContainer.gameObject.SetActive(true);
int maxDay = System.DateTime.DaysInMonth(_SelectYear, _SelectMonth);
List<int> dayList = new List<int>();
for (int i = 1; i <= maxDay; ++i)
{
dayList.Add(i);
}
_DayContainer.InitSelectContent(dayList, new List<int>() { _SelectDay }, DaySelected);
}
private void DaySelected(object selectGO)
{
int day = (int)selectGO;
_DayTx.text = day.ToString();
if (_SelectDay != day)
{
_DayContainer.gameObject.SetActive(false);
}
_SelectDay = day;
}
public void HideContainers()
{
_YearContainer.gameObject.SetActive(false);
_MonthContainer.gameObject.SetActive(false);
_DayContainer.gameObject.SetActive(false);
}
public void OnOkClick()
{
System.DateTime date = new System.DateTime(_SelectYear, _SelectMonth, _SelectDay);
_DaySelectedCallBack(date);
CloseWindow();
}
public void CloseWindow()
{
UIManager.CloseUI(UIInfo.DaySelectRoot);
}
#endregion
}