| | |
| | | using System; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using System.Collections; |
| | | |
| | | namespace Snxxz.UI |
| | | { |
| | | public class SetFreeTimeWin : Window |
| | | { |
| | | [SerializeField] Text titleText; |
| | | [SerializeField] ScrollerController hourlistCtrl; |
| | | [SerializeField] ScrollerController minutelistCtrl; |
| | | [SerializeField] Button closeBtn; |
| | | [SerializeField] Button sureBtn; |
| | | [SerializeField] Button cancelBtn; |
| | | [SerializeField] Transform selectTimePos; |
| | | [SerializeField] CanvasGroup canvas; |
| | | |
| | | static string titleName; |
| | | static int timeType; |
| | | static int curHour; |
| | | static int curMinute; |
| | | bool isOpen = true; |
| | | |
| | | public static int DownNum = 2; |
| | | SetPrivateModel privateModel { get { return ModelCenter.Instance.GetModel<SetPrivateModel>(); } } |
| | | |
| | | protected override void BindController() |
| | | { |
| | | hourlistCtrl.OnRefreshCell += RefreshHourTimeCell; |
| | | minutelistCtrl.OnRefreshCell += RefreshMinuteTimeCell; |
| | | } |
| | | |
| | | protected override void AddListeners() |
| | | { |
| | | closeBtn.AddListener(CloseClick); |
| | | cancelBtn.AddListener(CloseClick); |
| | | sureBtn.AddListener(ClickSureBtn); |
| | | } |
| | | |
| | | protected override void OnPreOpen() |
| | | { |
| | | canvas.alpha = 0; |
| | | isOpen = true; |
| | | titleText.text = titleName; |
| | | CreateHourCell(); |
| | | CreateMinuteCell(); |
| | | } |
| | | protected override void OnAfterOpen() |
| | | { |
| | | StartCoroutine(DelayHourJump()); |
| | | StartCoroutine(DelayMinuteJump()); |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | |
| | | } |
| | | protected override void OnAfterClose() |
| | | { |
| | | |
| | | } |
| | | |
| | | public static void SetTitleName(int type,int hour,int minute) |
| | | { |
| | | timeType = type; |
| | | switch(type) |
| | | { |
| | | case 1: |
| | | titleName = Language.Get("SetUpPrivate104"); |
| | | break; |
| | | case 2: |
| | | titleName = Language.Get("SetUpPrivate105"); |
| | | break; |
| | | } |
| | | |
| | | curHour = hour; |
| | | curMinute = minute; |
| | | if(!WindowCenter.Instance.CheckOpen<SetFreeTimeWin>()) |
| | | { |
| | | WindowCenter.Instance.Open<SetFreeTimeWin>(); |
| | | } |
| | | } |
| | | |
| | | private void CreateHourCell() |
| | | { |
| | | hourlistCtrl.Refresh(); |
| | | for(int i = 0; i < 24;i++) |
| | | { |
| | | hourlistCtrl.AddCell(ScrollerDataType.Header,i); |
| | | } |
| | | hourlistCtrl.Restart(); |
| | | |
| | | } |
| | | |
| | | private void CreateMinuteCell() |
| | | { |
| | | minutelistCtrl.Refresh(); |
| | | for (int i = 0; i < 60; i++) |
| | | { |
| | | minutelistCtrl.AddCell(ScrollerDataType.Header, i); |
| | | } |
| | | minutelistCtrl.Restart(); |
| | | |
| | | } |
| | | |
| | | IEnumerator DelayHourJump() |
| | | { |
| | | yield return null; |
| | | for (int i = 0; i < 24; i++) |
| | | { |
| | | int hour = i % 24; |
| | | if (hour == curHour) |
| | | { |
| | | hourlistCtrl.JumpIndex(i - DownNum); |
| | | break; |
| | | } |
| | | } |
| | | canvas.alpha = 1; |
| | | yield return null; |
| | | isOpen = false; |
| | | |
| | | } |
| | | |
| | | IEnumerator DelayMinuteJump() |
| | | { |
| | | yield return null; |
| | | for (int i = 0; i < 60; i++) |
| | | { |
| | | int minute = i % 60; |
| | | if (minute == curMinute) |
| | | { |
| | | minutelistCtrl.JumpIndex(i - DownNum); |
| | | break; |
| | | } |
| | | } |
| | | canvas.alpha = 1; |
| | | yield return null; |
| | | isOpen = false; |
| | | |
| | | } |
| | | private void RefreshHourTimeCell(ScrollerDataType type, CellView cell) |
| | | { |
| | | FreeTimeCell timeCell = cell.GetComponent<FreeTimeCell>(); |
| | | int curNum = cell.index % 24; |
| | | if (isOpen) |
| | | { |
| | | timeCell.SetModel(TimeType.Hour, curNum, curHour); |
| | | } |
| | | else |
| | | { |
| | | timeCell.SetModel(TimeType.Hour, curNum,GetSelectNum(TimeType.Hour)); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void RefreshMinuteTimeCell(ScrollerDataType type, CellView cell) |
| | | { |
| | | FreeTimeCell timeCell = cell.GetComponent<FreeTimeCell>(); |
| | | int curNum = cell.index % 60; |
| | | if (isOpen) |
| | | { |
| | | timeCell.SetModel(TimeType.Minute, curNum, curMinute); |
| | | } |
| | | else |
| | | { |
| | | timeCell.SetModel(TimeType.Minute, curNum, GetSelectNum(TimeType.Minute)); |
| | | } |
| | | } |
| | | |
| | | public int GetSelectNum(TimeType timeType) |
| | | { |
| | | Transform content = null; |
| | | switch (timeType) |
| | | { |
| | | case TimeType.Hour: |
| | | content = hourlistCtrl.mScrollRect.content; |
| | | break; |
| | | case TimeType.Minute: |
| | | content = minutelistCtrl.mScrollRect.content; |
| | | break; |
| | | } |
| | | int childCount = content.childCount; |
| | | int minIndex = 0; |
| | | int maxIndex = 0; |
| | | for (int i = 0; i < childCount; i++) |
| | | { |
| | | FreeTimeCell timeCell = content.GetChild(i).GetComponent<FreeTimeCell>(); |
| | | if (timeCell != null) |
| | | { |
| | | minIndex = timeCell.index; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (int i = childCount - 1; i > -1; i--) |
| | | { |
| | | FreeTimeCell timeCell = content.GetChild(i).GetComponent<FreeTimeCell>(); |
| | | if (timeCell != null) |
| | | { |
| | | maxIndex = timeCell.index; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | int midIndex = 0; |
| | | switch (timeType) |
| | | { |
| | | case TimeType.Hour: |
| | | if(maxIndex < minIndex) |
| | | { |
| | | maxIndex += 24; |
| | | } |
| | | midIndex = (minIndex + maxIndex) / 2; |
| | | curHour = midIndex % 24; |
| | | return curHour; |
| | | case TimeType.Minute: |
| | | if (maxIndex < minIndex) |
| | | { |
| | | maxIndex += 60; |
| | | } |
| | | midIndex = (minIndex + maxIndex) / 2; |
| | | curMinute = midIndex % 60; |
| | | return curMinute; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | private void ClickSureBtn() |
| | | { |
| | | privateModel.SetRefreshFreeTimeEvent(timeType, curHour,curMinute); |
| | | CloseClick(); |
| | | } |
| | | } |
| | | } |
| | | using System;
|
| | | using UnityEngine;
|
| | | using UnityEngine.UI;
|
| | | using System.Collections;
|
| | |
|
| | | namespace Snxxz.UI
|
| | | {
|
| | | public class SetFreeTimeWin : Window
|
| | | {
|
| | | [SerializeField] Text titleText;
|
| | | [SerializeField] ScrollerController hourlistCtrl;
|
| | | [SerializeField] ScrollerController minutelistCtrl;
|
| | | [SerializeField] Button closeBtn;
|
| | | [SerializeField] Button sureBtn;
|
| | | [SerializeField] Button cancelBtn;
|
| | | [SerializeField] Transform selectTimePos;
|
| | | [SerializeField] CanvasGroup canvas;
|
| | |
|
| | | static string titleName;
|
| | | static int timeType;
|
| | | static int curHour;
|
| | | static int curMinute;
|
| | | bool isOpen = true;
|
| | |
|
| | | public static int DownNum = 2;
|
| | | SetPrivateModel privateModel { get { return ModelCenter.Instance.GetModel<SetPrivateModel>(); } }
|
| | |
|
| | | protected override void BindController()
|
| | | {
|
| | | hourlistCtrl.OnRefreshCell += RefreshHourTimeCell;
|
| | | minutelistCtrl.OnRefreshCell += RefreshMinuteTimeCell;
|
| | | }
|
| | |
|
| | | protected override void AddListeners()
|
| | | {
|
| | | closeBtn.AddListener(CloseClick);
|
| | | cancelBtn.AddListener(CloseClick);
|
| | | sureBtn.AddListener(ClickSureBtn);
|
| | | }
|
| | |
|
| | | protected override void OnPreOpen()
|
| | | {
|
| | | canvas.alpha = 0;
|
| | | isOpen = true;
|
| | | titleText.text = titleName;
|
| | | CreateHourCell();
|
| | | CreateMinuteCell();
|
| | | }
|
| | | protected override void OnAfterOpen()
|
| | | {
|
| | | StartCoroutine(DelayHourJump());
|
| | | StartCoroutine(DelayMinuteJump());
|
| | | }
|
| | |
|
| | | protected override void OnPreClose()
|
| | | {
|
| | | |
| | | }
|
| | | protected override void OnAfterClose()
|
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | public static void SetTitleName(int type,int hour,int minute)
|
| | | {
|
| | | timeType = type;
|
| | | switch(type)
|
| | | {
|
| | | case 1:
|
| | | titleName = Language.Get("SetUpPrivate104");
|
| | | break;
|
| | | case 2:
|
| | | titleName = Language.Get("SetUpPrivate105");
|
| | | break;
|
| | | }
|
| | | |
| | | curHour = hour;
|
| | | curMinute = minute;
|
| | | if(!WindowCenter.Instance.CheckOpen<SetFreeTimeWin>())
|
| | | {
|
| | | WindowCenter.Instance.Open<SetFreeTimeWin>();
|
| | | }
|
| | | }
|
| | |
|
| | | private void CreateHourCell()
|
| | | {
|
| | | hourlistCtrl.Refresh();
|
| | | for(int i = 0; i < 24;i++)
|
| | | {
|
| | | hourlistCtrl.AddCell(ScrollerDataType.Header,i);
|
| | | }
|
| | | hourlistCtrl.Restart();
|
| | | |
| | | }
|
| | |
|
| | | private void CreateMinuteCell()
|
| | | {
|
| | | minutelistCtrl.Refresh();
|
| | | for (int i = 0; i < 60; i++)
|
| | | {
|
| | | minutelistCtrl.AddCell(ScrollerDataType.Header, i);
|
| | | }
|
| | | minutelistCtrl.Restart();
|
| | |
|
| | | }
|
| | |
|
| | | IEnumerator DelayHourJump()
|
| | | {
|
| | | yield return null;
|
| | | for (int i = 0; i < 24; i++)
|
| | | {
|
| | | int hour = i % 24;
|
| | | if (hour == curHour)
|
| | | {
|
| | | hourlistCtrl.JumpIndex(i - DownNum);
|
| | | break;
|
| | | }
|
| | | }
|
| | | canvas.alpha = 1;
|
| | | yield return null;
|
| | | isOpen = false;
|
| | |
|
| | | }
|
| | |
|
| | | IEnumerator DelayMinuteJump()
|
| | | {
|
| | | yield return null;
|
| | | for (int i = 0; i < 60; i++)
|
| | | {
|
| | | int minute = i % 60;
|
| | | if (minute == curMinute)
|
| | | {
|
| | | minutelistCtrl.JumpIndex(i - DownNum);
|
| | | break;
|
| | | }
|
| | | }
|
| | | canvas.alpha = 1;
|
| | | yield return null;
|
| | | isOpen = false;
|
| | |
|
| | | }
|
| | | private void RefreshHourTimeCell(ScrollerDataType type, CellView cell)
|
| | | {
|
| | | FreeTimeCell timeCell = cell.GetComponent<FreeTimeCell>();
|
| | | int curNum = cell.index % 24;
|
| | | if (isOpen)
|
| | | {
|
| | | timeCell.SetModel(TimeType.Hour, curNum, curHour);
|
| | | }
|
| | | else
|
| | | {
|
| | | timeCell.SetModel(TimeType.Hour, curNum,GetSelectNum(TimeType.Hour));
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | private void RefreshMinuteTimeCell(ScrollerDataType type, CellView cell)
|
| | | {
|
| | | FreeTimeCell timeCell = cell.GetComponent<FreeTimeCell>();
|
| | | int curNum = cell.index % 60;
|
| | | if (isOpen)
|
| | | {
|
| | | timeCell.SetModel(TimeType.Minute, curNum, curMinute);
|
| | | }
|
| | | else
|
| | | {
|
| | | timeCell.SetModel(TimeType.Minute, curNum, GetSelectNum(TimeType.Minute));
|
| | | }
|
| | | }
|
| | |
|
| | | public int GetSelectNum(TimeType timeType)
|
| | | {
|
| | | Transform content = null;
|
| | | switch (timeType)
|
| | | {
|
| | | case TimeType.Hour:
|
| | | content = hourlistCtrl.mScrollRect.content;
|
| | | break;
|
| | | case TimeType.Minute:
|
| | | content = minutelistCtrl.mScrollRect.content;
|
| | | break;
|
| | | }
|
| | | int childCount = content.childCount;
|
| | | int minIndex = 0;
|
| | | int maxIndex = 0;
|
| | | for (int i = 0; i < childCount; i++)
|
| | | {
|
| | | FreeTimeCell timeCell = content.GetChild(i).GetComponent<FreeTimeCell>();
|
| | | if (timeCell != null)
|
| | | {
|
| | | minIndex = timeCell.index;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | for (int i = childCount - 1; i > -1; i--)
|
| | | {
|
| | | FreeTimeCell timeCell = content.GetChild(i).GetComponent<FreeTimeCell>();
|
| | | if (timeCell != null)
|
| | | {
|
| | | maxIndex = timeCell.index;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | int midIndex = 0;
|
| | | switch (timeType)
|
| | | {
|
| | | case TimeType.Hour:
|
| | | if(maxIndex < minIndex)
|
| | | {
|
| | | maxIndex += 24;
|
| | | }
|
| | | midIndex = (minIndex + maxIndex) / 2;
|
| | | curHour = midIndex % 24;
|
| | | return curHour;
|
| | | case TimeType.Minute:
|
| | | if (maxIndex < minIndex)
|
| | | {
|
| | | maxIndex += 60;
|
| | | }
|
| | | midIndex = (minIndex + maxIndex) / 2;
|
| | | curMinute = midIndex % 60;
|
| | | return curMinute;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | private void ClickSureBtn()
|
| | | {
|
| | | privateModel.SetRefreshFreeTimeEvent(timeType, curHour,curMinute);
|
| | | CloseClick();
|
| | | }
|
| | | }
|
| | | }
|