Beispiel #1
0
    void update_days(bool flag)
    {
        GameObject days_obj = transform.FindChild("days").gameObject;
        GameObject select   = null;
        int        maxDays  = DateTime.DaysInMonth(_year, _month);
        DateTime   fisrt    = new DateTime(_year, _month, 1);
        DayOfWeek  week     = fisrt.DayOfWeek;
        int        start    = MyUtilTools.GetWeekDays(week);//这个月的第一天
        int        preMonth = _month - 1;
        int        preYear  = _year;

        if (preMonth == 0)
        {
            preMonth = 12;
            preYear--;
        }
        int  stand          = start == 0 ? 1 : 0;
        int  temp           = start == 0 ? 7 : start;
        int  preLastDay     = DateTime.DaysInMonth(preYear, preMonth);
        int  dayIndex       = preLastDay - temp + 1;
        int  dayCount       = 0;
        int  nextMonth      = _month;
        int  nextYear       = _year;
        bool nextMonthStart = false;
        bool thisMonthStart = false;

        for (int i = 0; i < 6; i++)
        {
            GameObject row_obj = days_obj.transform.FindChild("row" + i).gameObject;
            if (i <= stand)
            {
                for (int j = 0; j < 7; j++)
                {
                    GameObject day = row_obj.transform.FindChild("col" + j).gameObject;
                    if (flag)
                    {
                        UIButton      button       = day.GetComponent <UIButton>();
                        EventDelegate event_select = new EventDelegate(this, "doSelect");
                        event_select.parameters[0]     = new EventDelegate.Parameter();
                        event_select.parameters[0].obj = day;
                        button.onClick.Add(event_select);
                    }
                    if (dayIndex < preLastDay - 1 && !thisMonthStart)
                    {
                        day.SetActive(false);
                    }
                    else
                    {
                        if (!thisMonthStart && dayIndex > preLastDay)
                        {
                            thisMonthStart = true;
                            dayIndex       = 1;
                            preMonth++;
                            if (preMonth > 12)
                            {
                                preMonth = 1;
                                preYear++;
                            }
                        }
                        day.SetActive(true);
                        UILabel label = day.transform.FindChild("gl").GetComponent <UILabel>();
                        label.text = dayIndex + "";
                        label      = day.transform.FindChild("nl").GetComponent <UILabel>();
                        if (dayIndex == DateTime.Now.Day && preMonth == DateTime.Now.Month && preYear == DateTime.Now.Year)
                        {
                            label.text = "今天";
                        }
                        else
                        {
                            DateTime dateTime = DateTime.Parse(preYear + "-" + MyUtilTools.numToString(preMonth) + "-" + MyUtilTools.numToString(dayIndex) + " 00:00:00");
                            CNDate   cnDate   = ChinaDate.getChinaDate(dateTime);
                            if (!cnDate.cnFtvl.Equals(""))
                            {
                                label.text = cnDate.cnFtvl;
                            }
                            else if (!cnDate.cnFtvs.Equals(""))
                            {
                                label.text = cnDate.cnFtvs;
                            }
                            else if (!cnDate.cnSolarTerm.Equals(""))
                            {
                                label.text = cnDate.cnSolarTerm;
                            }
                            else
                            {
                                label.text = cnDate.cnStrDay;
                            }
                        }
                        if (selectIndex == -1 && _day == dayIndex && nextMonth == _month && nextYear == _year)
                        {
                            selectIndex = dayCount;
                        }
                    }
                    CalendarData cd = day.GetComponent <CalendarData>();
                    cd.Value = MyUtilTools.numToString(preYear) + "-" + MyUtilTools.numToString(preMonth) + "-" + MyUtilTools.numToString(dayIndex);
                    cd.Index = dayCount;
                    dayIndex++;
                    dayCount++;
                }
            }
            else
            {
                for (int j = 0; j < 7; j++)
                {
                    GameObject day = row_obj.transform.FindChild("col" + j).gameObject;
                    if (flag)
                    {
                        UIButton      button       = day.GetComponent <UIButton>();
                        EventDelegate event_select = new EventDelegate(this, "doSelect");
                        event_select.parameters[0]     = new EventDelegate.Parameter();
                        event_select.parameters[0].obj = day;
                        button.onClick.Add(event_select);
                    }
                    if (nextMonthStart)
                    {
                        day.SetActive(false);
                    }
                    else
                    {
                        day.SetActive(true);
                        UILabel label = day.transform.FindChild("gl").GetComponent <UILabel>();
                        label.text = dayIndex + "";
                        label      = day.transform.FindChild("nl").GetComponent <UILabel>();
                        if (dayIndex == DateTime.Now.Day && nextMonth == DateTime.Now.Month && nextYear == DateTime.Now.Year)
                        {
                            label.text = "今天";
                        }
                        else
                        {
                            DateTime dateTime = DateTime.Parse(nextYear + "-" + MyUtilTools.numToString(nextMonth) + "-" + MyUtilTools.numToString(dayIndex) + " 00:00:00");
                            CNDate   cnDate   = ChinaDate.getChinaDate(dateTime);
                            if (!cnDate.cnFtvl.Equals(""))
                            {
                                label.text = cnDate.cnFtvl;
                            }
                            else if (!cnDate.cnFtvs.Equals(""))
                            {
                                label.text = cnDate.cnFtvs;
                            }
                            else if (!cnDate.cnSolarTerm.Equals(""))
                            {
                                label.text = cnDate.cnSolarTerm;
                            }
                            else
                            {
                                label.text = cnDate.cnStrDay;
                            }
                        }
                        if (selectIndex == -1 && _day == dayIndex && nextMonth == _month && nextYear == _year)
                        {
                            selectIndex = dayCount;
                        }
                        CalendarData cd = day.GetComponent <CalendarData>();
                        cd.Value = MyUtilTools.numToString(nextYear) + "-" + MyUtilTools.numToString(nextMonth) + "-" + MyUtilTools.numToString(dayIndex);
                        cd.Index = dayCount;
                        dayIndex++;
                        if (dayIndex > maxDays)
                        {//下一个月的天数
                            nextMonthStart = true;
                            dayIndex       = 1;
                            nextMonth++;
                            if (nextMonth > 12)
                            {
                                nextMonth = 1;
                                nextYear++;
                            }
                        }
                    }
                    dayCount++;
                }
            }
        }
        int row = selectIndex / 7;
        int col = selectIndex % 7;

        select = days_obj.transform.FindChild("row" + row).FindChild("col" + col).gameObject;
        if (flag)
        {
            selectIndex = -1;
        }
        doSelect(select);
    }
Beispiel #2
0
    void _update()
    {
        if (list_container == null)
        {
            list_container = needshow[0].transform.FindChild("list").FindChild("body").FindChild("container");
            texture1       = Resources.Load <Texture>("pic/time-event1");
            texture2       = Resources.Load <Texture>("pic/time-event2");
            texture3       = Resources.Load <Texture>("pic/time-event3");
            texture4       = Resources.Load <Texture>("pic/time-event4");
            TimeLineRefresh refresh = needshow[0].AddComponent <TimeLineRefresh>();
            refresh.timeEvent = this;
        }
        if (Calendar.selectTexture == null)
        {
            Calendar.selectTexture = Resources.Load <Texture>("pic/time-sb");
        }
        list_container.parent.GetComponent <UIPanel>().clipOffset = Vector2.zero;
        list_container.parent.localPosition = new Vector3(0, 0, 0);
        UILabel year_label = list_container.FindChild("up").GetComponent <UILabel>();

        year_label.text = MyUtilTools.numToString(_year) + "年" + MyUtilTools.numToString(_month) + "月";
        Transform days_trans = list_container.FindChild("days");
        int       maxDays    = DateTime.DaysInMonth(_year, _month);
        DateTime  fisrt      = new DateTime(_year, _month, 1);
        DayOfWeek week       = fisrt.DayOfWeek;
        int       start      = MyUtilTools.GetWeekDays(week);//这个月的第一天
        int       preMonth   = _month - 1;
        int       preYear    = _year;

        if (preMonth == 0)
        {
            preMonth = 12;
            preYear--;
        }
        int  stand          = start == 0 ? 1 : 0;
        int  temp           = start == 0 ? 7 : start;
        int  preLastDay     = DateTime.DaysInMonth(preYear, preMonth);
        int  dayIndex       = preLastDay - temp + 1;
        int  dayCount       = 0;
        int  nextMonth      = _month;
        int  nextYear       = _year;
        bool nextMonthStart = false;
        bool thisMonthStart = false;

        for (int i = 0; i < 6; i++)
        {
            GameObject row_obj = days_trans.FindChild("row" + i).gameObject;
            if (i <= stand)
            {
                for (int j = 0; j < 7; j++)
                {
                    GameObject day    = row_obj.transform.FindChild("col" + j).gameObject;
                    UIButton   button = day.GetComponent <UIButton>();
                    if (button.onClick.Count == 0)
                    {
                        EventDelegate event_select = new EventDelegate(this, "doSelect");
                        event_select.parameters[0]     = new EventDelegate.Parameter();
                        event_select.parameters[0].obj = day;
                        button.onClick.Add(event_select);
                    }
                    if (dayIndex < preLastDay - 1 && !thisMonthStart)
                    {
                        day.SetActive(false);
                    }
                    else
                    {
                        if (!thisMonthStart && dayIndex > preLastDay)
                        {
                            thisMonthStart = true;
                            dayIndex       = 1;
                            preMonth++;
                            if (preMonth > 12)
                            {
                                preMonth = 1;
                                preYear++;
                            }
                        }
                        day.SetActive(true);
                        UILabel label = day.transform.FindChild("gl").GetComponent <UILabel>();
                        label.text = dayIndex + "";
                        label      = day.transform.FindChild("nl").GetComponent <UILabel>();
                        if (dayIndex == DateTime.Now.Day && preMonth == DateTime.Now.Month && preYear == DateTime.Now.Year)
                        {
                            label.text = "今天";
                        }
                        else
                        {
                            DateTime dateTime = DateTime.Parse(preYear + "-" + MyUtilTools.numToString(preMonth) + "-" + MyUtilTools.numToString(dayIndex) + " 00:00:00");
                            CNDate   cnDate   = ChinaDate.getChinaDate(dateTime);
                            if (!cnDate.cnFtvl.Equals(""))
                            {
                                label.text = cnDate.cnFtvl;
                            }
                            else if (!cnDate.cnFtvs.Equals(""))
                            {
                                label.text = cnDate.cnFtvs;
                            }
                            else if (!cnDate.cnSolarTerm.Equals(""))
                            {
                                label.text = cnDate.cnSolarTerm;
                            }
                            else
                            {
                                label.text = cnDate.cnStrDay;
                            }
                        }
                        if (selectIndex == -1 && _day == dayIndex && nextMonth == _month && nextYear == _year)
                        {
                            selectIndex = dayCount;
                        }
                    }
                    _update_flags(day, preYear, preMonth, dayIndex);
                    CalendarData cd = day.GetComponent <CalendarData>();
                    cd.Value = MyUtilTools.numToString(preYear) + "-" + MyUtilTools.numToString(preMonth) + "-" + MyUtilTools.numToString(dayIndex);
                    cd.Index = dayCount;
                    dayIndex++;
                    dayCount++;
                }
            }
            else
            {
                for (int j = 0; j < 7; j++)
                {
                    GameObject day    = row_obj.transform.FindChild("col" + j).gameObject;
                    UIButton   button = day.GetComponent <UIButton>();
                    if (button.onClick.Count == 0)
                    {
                        EventDelegate event_select = new EventDelegate(this, "doSelect");
                        event_select.parameters[0]     = new EventDelegate.Parameter();
                        event_select.parameters[0].obj = day;
                        button.onClick.Add(event_select);
                    }
                    if (nextMonthStart)
                    {
                        day.SetActive(false);
                    }
                    else
                    {
                        day.SetActive(true);
                        UILabel label = day.transform.FindChild("gl").GetComponent <UILabel>();
                        label.text = dayIndex + "";
                        label      = day.transform.FindChild("nl").GetComponent <UILabel>();
                        if (dayIndex == DateTime.Now.Day && nextMonth == DateTime.Now.Month && nextYear == DateTime.Now.Year)
                        {
                            label.text = "今天";
                        }
                        else
                        {
                            DateTime dateTime = DateTime.Parse(nextYear + "-" + MyUtilTools.numToString(nextMonth) + "-" + MyUtilTools.numToString(dayIndex) + " 00:00:00");
                            CNDate   cnDate   = ChinaDate.getChinaDate(dateTime);
                            if (!cnDate.cnFtvl.Equals(""))
                            {
                                label.text = cnDate.cnFtvl;
                            }
                            else if (!cnDate.cnFtvs.Equals(""))
                            {
                                label.text = cnDate.cnFtvs;
                            }
                            else if (!cnDate.cnSolarTerm.Equals(""))
                            {
                                label.text = cnDate.cnSolarTerm;
                            }
                            else
                            {
                                label.text = cnDate.cnStrDay;
                            }
                        }
                        if (selectIndex == -1 && _day == dayIndex && nextMonth == _month && nextYear == _year)
                        {
                            selectIndex = dayCount;
                        }
                        _update_flags(day, nextYear, nextMonth, dayIndex);
                        CalendarData cd = day.GetComponent <CalendarData>();
                        cd.Value = MyUtilTools.numToString(nextYear) + "-" + MyUtilTools.numToString(nextMonth) + "-" + MyUtilTools.numToString(dayIndex);
                        cd.Index = dayCount;
                        dayIndex++;
                        if (dayIndex > maxDays)
                        {//下一个月的天数
                            nextMonthStart = true;
                            dayIndex       = 1;
                            nextMonth++;
                            if (nextMonth > 12)
                            {
                                nextMonth = 1;
                                nextYear++;
                            }
                        }
                    }
                    dayCount++;
                }
            }
        }
        int        row    = selectIndex / 7;
        int        col    = selectIndex % 7;
        GameObject select = days_trans.FindChild("row" + row).FindChild("col" + col).gameObject;

        doSelect(select);
    }