public void OnPointerDown(CalenderButton chosenCalenderButton, DateTime chosenDate, Calender calender) { // clears selection if (m_StartDate != null && m_EndDate != null) { m_StartDate_SelectedBTN.ResetToOriginal(); m_EndDate_SelectedBTN.ResetToOriginal(); m_StartDate = null; m_EndDate = null; // don't return on this one } if (m_StartDate == null && m_EndDate == null) { if (chosenCalenderButton.CurrentState != CalenderButton.State.Disabled) { m_StartDate = chosenDate; m_StartDate_SelectedBTN = chosenCalenderButton; CalendersUpdated?.Invoke(m_StartDate, m_EndDate); chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); } return; } // revert, if second date is selected is less that the first chosen ddate if (m_StartDate != null && chosenDate <= m_StartDate && m_EndDate == null) { if (chosenCalenderButton.CurrentState != CalenderButton.State.Disabled) { // revert previous selected start date m_StartDate_SelectedBTN.ResetToOriginal(); m_StartDate = chosenDate; m_StartDate_SelectedBTN = chosenCalenderButton; CalendersUpdated?.Invoke(m_StartDate, m_EndDate); chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); } return; } if (m_StartDate != null && m_EndDate == null) { m_EndDate = chosenDate; // select end button chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); m_EndDate_SelectedBTN = chosenCalenderButton; CalendersUpdated?.Invoke(m_StartDate, m_EndDate); if (m_CloseOnLastSelection) { FW_Calender.gameObject.SetActive(false); SW_Calender.gameObject.SetActive(false); } return; } }
public void OnPointerDown(CalenderButton chosenCalenderButton, DateTime chosenDate, Calender calender) { // clears selection if (m_StartDate != null && m_EndDate != null) { for (int i = 0; i < 42; i++) { m_Calender.CalenderButtons[i].ResetToOriginal(); } m_StartDate = null; m_EndDate = null; // don't return on this one } // intiate first click if (m_StartDate == null && m_EndDate == null) { if (chosenCalenderButton.CurrentState != CalenderButton.State.Disabled) { m_StartDate = chosenDate; m_StartDate_SelectedBTN = chosenCalenderButton; CalendersUpdated?.Invoke(m_StartDate, m_EndDate); chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); } return; } if (m_StartDate != null && chosenDate <= m_StartDate && m_EndDate == null) { if (chosenCalenderButton.CurrentState != CalenderButton.State.Disabled) { // revert previous selected start date m_StartDate_SelectedBTN.ResetToOriginal(); m_StartDate = chosenDate; m_StartDate_SelectedBTN = chosenCalenderButton; CalendersUpdated?.Invoke(m_StartDate, m_EndDate); chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); } return; } // initiate second click if (m_StartDate != null && m_EndDate == null) { m_EndDate = chosenDate; // select end button chosenCalenderButton.UpdateState(CalenderButton.State.Selected, chosenDate, m_StartDate, m_EndDate); DateTime date = m_StartDate.Value; for (int i = 0; i < (m_EndDate - m_StartDate).Value.TotalDays + 1; i++) { CalenderButton calenderButton; calenderButton = m_Calender.CalenderButtons.Where(x => x.Date == date && x.CurrentState != CalenderButton.State.Disabled).FirstOrDefault(); if (calenderButton != null) { calenderButton.UpdateState(CalenderButton.State.Highlighted, date, m_StartDate, m_EndDate); } date = date.AddDays(1); } CalendersUpdated?.Invoke(m_StartDate, m_EndDate); if (m_CloseOnLastSelection) { m_Calender.gameObject.SetActive(false); } return; } }