Author Topic: Does NGUI come with Calendar widget??  (Read 6661 times)

weilies

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Does NGUI come with Calendar widget??
« on: January 29, 2016, 12:31:37 AM »
Dear gurus,

i need a calendar field, https://jqueryui.com/datepicker/
How can i create one in NGUI?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does NGUI come with Calendar widget??
« Reply #1 on: January 31, 2016, 06:07:46 AM »
NGUI doesn't come with this, no. You can create one by making a panel with a grid of buttons. Write a script that will change the numbers on buttons and enable/disable them as needed. Figuring out which #s to show and which buttons to disable would be your code -- based on what month you want to show and what day of the week each day falls on.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Does NGUI come with Calendar widget??
« Reply #2 on: February 01, 2016, 03:33:38 AM »
  1. //header
  2. for (int i = 0; i < 7; i++)
  3. {
  4.         GameObject row = NGUITools.AddChild(grid_calendar.gameObject, prefab_cell);
  5.  
  6.         row.SetActive(true);
  7.  
  8.         row.name = string.Format("header - {0}", (DayOfWeek)i);
  9.         UILabel label = row.transform.FindChild("Label").GetComponent<UILabel>();
  10.         label.text = string.Format("{0}", ((DayOfWeek)i).ToString().Substring(0, 2));
  11. }
  12.  
  13. //empty objects before 1st of month
  14. DateTime first = new DateTime(datetime.Year, datetime.Month, 1);
  15. for (int i = 0; i < (int)first.DayOfWeek; i++)
  16.  
  17. for (int i = 1; i < DateTime.DaysInMonth(datetime.Year, datetime.Month); i++)

DateTime has everything you need!

« Last Edit: February 01, 2016, 03:58:58 AM by devomage »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does NGUI come with Calendar widget??
« Reply #3 on: February 04, 2016, 08:49:55 PM »
Nice!

weilies

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Does NGUI come with Calendar widget??
« Reply #4 on: February 24, 2016, 12:28:26 AM »
  1. //header
  2. for (int i = 0; i < 7; i++)
  3. {
  4.         GameObject row = NGUITools.AddChild(grid_calendar.gameObject, prefab_cell);
  5.  
  6.         row.SetActive(true);
  7.  
  8.         row.name = string.Format("header - {0}", (DayOfWeek)i);
  9.         UILabel label = row.transform.FindChild("Label").GetComponent<UILabel>();
  10.         label.text = string.Format("{0}", ((DayOfWeek)i).ToString().Substring(0, 2));
  11. }
  12.  
  13. //empty objects before 1st of month
  14. DateTime first = new DateTime(datetime.Year, datetime.Month, 1);
  15. for (int i = 0; i < (int)first.DayOfWeek; i++)
  16.  
  17. for (int i = 1; i < DateTime.DaysInMonth(datetime.Year, datetime.Month); i++)

DateTime has everything you need!

sorry, but i am not sure how to add this into my current scene, do u have a scene file for sharing? ^^

Thanks!

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Does NGUI come with Calendar widget??
« Reply #5 on: February 24, 2016, 01:09:35 AM »
I'd prefer not for this example. 

The code is fairly straight forward...  a simple button as the prefab in a 7x grid.