7 protected string m_sComboBaseName;
10 protected string m_sLabelHolderBaseName;
13 protected string m_sLabelName;
16 protected ref array<int> m_aDayArray;
19 protected float m_fMonthWidgetFill;
21 protected TextWidget m_Label0;
22 protected TextWidget m_Label1;
23 protected TextWidget m_Label2;
32 protected string m_sDateOrder;
34 protected TimeAndWeatherManagerEntity m_TimeAndWeatherManager;
39 super.Init(w, attribute);
42 m_TimeAndWeatherManager = world.GetTimeAndWeatherManager();
44 if (!m_TimeAndWeatherManager)
46 Print(
"SCR_DateAttributeUIComponent could not find GetTimeAndWeatherManager!", LogLevel.ERROR);
51 Widget dateHolderWidget = w.FindAnyWidget(m_sUiComponentName);
52 if (!dateHolderWidget)
return;
55 if (!dateHolder)
return;
58 Widget labelHolder0 = w.FindAnyWidget(m_sLabelHolderBaseName + 0);
59 Widget labelHolder1 = w.FindAnyWidget(m_sLabelHolderBaseName + 1);
60 Widget labelHolder2 = w.FindAnyWidget(m_sLabelHolderBaseName + 2);
62 if (!labelHolder0 || !labelHolder1 || !labelHolder2)
return;
64 m_Label0 = TextWidget.Cast(labelHolder0.FindAnyWidget(m_sLabelName));
65 m_Label1 = TextWidget.Cast(labelHolder1.FindAnyWidget(m_sLabelName));
66 m_Label2 = TextWidget.Cast(labelHolder2.FindAnyWidget(m_sLabelName));
68 if (!m_Label0 || !m_Label1 || !m_Label2)
return;
70 Widget comboBoxWidget0 = w.FindAnyWidget(m_sComboBaseName + 0);
71 Widget comboBoxWidget1 = w.FindAnyWidget(m_sComboBaseName + 1);
72 Widget comboBoxWidget2 = w.FindAnyWidget(m_sComboBaseName + 2);
74 if (!comboBoxWidget0 || !comboBoxWidget1 || !comboBoxWidget2)
return;
80 if (!m_comboBox0 || !m_comboBox1 || !m_comboBox2)
return;
86 array<ref SCR_BaseEditorAttributeEntry> entries =
new array<ref SCR_BaseEditorAttributeEntry>;
87 int entriesCount = attribute.GetEntries(entries);
88 string dayLabel, monthLabel, yearLabel;
93 if (!stringData)
return;
94 dateHolder.SetLabel(stringData.GetText());
97 if (!stringData)
return;
98 m_sDateOrder = stringData.GetText();
101 if (!stringData)
return;
102 dayLabel = stringData.GetText();
105 if (!stringData)
return;
106 monthLabel = stringData.GetText();
109 if (!stringData)
return;
110 yearLabel = stringData.GetText();
113 if (!m_aMonthData)
return;
116 if (!m_aYearData)
return;
119 FillMonthComboBox(GetCorrectComboBox(
"m"));
120 FillYearComboBox(GetCorrectComboBox(
"y"));
122 vector date = var.GetVector();
123 CreateDayList(GetCorrectComboBox(
"d"), date[1] +1, m_aYearData.GetEntry(date[2]),
false);
126 GetCorrectLabel(
"d").SetText(dayLabel);
127 GetCorrectLabel(
"m").SetText(monthLabel);
128 GetCorrectLabel(
"y").SetText(yearLabel);
131 SetMonthWidgetFillWeight();
134 m_comboBox0.m_OnChanged.Insert(OnComboBoxChanged);
135 m_comboBox1.m_OnChanged.Insert(OnComboBoxChanged);
136 m_comboBox2.m_OnChanged.Insert(OnComboBoxChanged);
144 vector date = var.GetVector();
145 SetDateComboBoxes(date);
146 CreateDayList(GetCorrectComboBox(
"d"), date[1] +1, m_aYearData.GetEntry(date[2]));
147 UpdateDateMoonPhaseIcon();
149 super.SetFromVar(var);
152 protected void CreateDayList(
SCR_ComboBoxIconComponent comboBox,
int currentMonth,
int currentYear,
bool setMoonIcon =
true)
154 int currentDateIndex = comboBox.GetCurrentIndex();
156 int count = m_aDayArray.Count();
158 if (count == 0)
return;
161 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
162 if (!timeManager)
return;
165 int day, month, year;
166 GetCorrectDateTime(daytime, day, month, year);
167 float timeZoneOffset = m_TimeAndWeatherManager.GetTimeZoneOffset();
168 float dstOffset = m_TimeAndWeatherManager.GetDSTOffset();
169 float latitude = m_TimeAndWeatherManager.GetCurrentLatitude();
172 ResourceName preIcon;
179 for (
int i = 0; i < count; i++)
182 if (m_aDayArray[i] >= 29 && !timeManager.CheckValidDate(currentYear, currentMonth, m_aDayArray[i]))
187 moonPhaseInfo = m_TimeAndWeatherManager.GetMoonPhaseInfoForDate(year, month, m_aDayArray[i], daytime, timeZoneOffset, dstOffset, latitude);
188 icon = moonPhaseInfo.GetIconPath();
196 comboBox.AddItemAndIcon(m_aDayArray[i].ToString(), icon,
rotation);
200 while (currentDateIndex >= comboBox.GetNumItems() && currentDateIndex > 0){
204 comboBox.SetCurrentItem(currentDateIndex);
207 protected void UpdateDateMoonPhaseIcon()
214 int day, month, year;
215 GetCorrectDateTime(daytime, day, month, year);
216 float timeZoneOffset = m_TimeAndWeatherManager.GetTimeZoneOffset();
217 float dstOffset = m_TimeAndWeatherManager.GetDSTOffset();
218 float latitude = m_TimeAndWeatherManager.GetCurrentLatitude();
221 SCR_MoonPhaseUIInfo moonPhaseInfo = m_TimeAndWeatherManager.GetMoonPhaseInfoForDate(year, month, day, daytime, timeZoneOffset, dstOffset, latitude);
222 ImageWidget icon = dayComboBox.GetIconWidget();
223 moonPhaseInfo.SetIconTo(icon);
224 icon.SetRotation(moonPhaseInfo.GetMoonphaseImageRotation());
225 icon.SetVisible(
true);
228 protected void GetCorrectDateTime(out
float daytime, out
int day, out
int month, out
int year)
234 if (!m_comboBox0 || !m_comboBox1 || !m_comboBox2)
237 daytime = dayTimeVar.GetFloat() / 3600;
238 day = GetCorrectComboBox(
"d").GetCurrentIndex() +1;
239 month = GetCorrectComboBox(
"m").GetCurrentIndex() +1;
240 year = m_aYearData.GetEntry(GetCorrectComboBox(
"y").GetCurrentIndex());
245 int count = m_aMonthData.GetCount();
248 for (
int i = 0; i < count; i++)
250 comboBox.AddItem(m_aMonthData.GetEntry(i));
256 int count = m_aYearData.GetCount();
259 for (
int i = 0; i < count; i++)
261 comboBox.AddItem(m_aYearData.GetEntry(i).ToString());
265 protected void SetMonthWidgetFillWeight()
267 LayoutSlot.SetFillWeight((GetCorrectLabel(
"m").GetParent()), m_fMonthWidgetFill);
268 LayoutSlot.SetFillWeight(GetCorrectComboBox(
"m").
GetRootWidget(), m_fMonthWidgetFill);
273 if (m_sDateOrder[0] == lookfor)
275 if (m_sDateOrder[1] == lookfor)
281 protected TextWidget GetCorrectLabel(
string lookfor)
283 if (m_sDateOrder[0] == lookfor)
285 if (m_sDateOrder[1] == lookfor)
291 protected void SetDateComboBoxes(vector date)
293 GetCorrectComboBox(
"d").SetCurrentItem(date[0]);
294 GetCorrectComboBox(
"m").SetCurrentItem(date[1]);
295 GetCorrectComboBox(
"y").SetCurrentItem(date[2]);
298 override bool OnChange(Widget w,
int x,
int y,
bool finished)
302 if (!attribute)
return false;
306 vector date = Vector(GetCorrectComboBox(
"d").GetCurrentIndex(), GetCorrectComboBox(
"m").GetCurrentIndex(), GetCorrectComboBox(
"y").GetCurrentIndex());
309 super.OnChange(w, x, y, finished);
316 if (comboBox == GetCorrectComboBox(
"m") || comboBox == GetCorrectComboBox(
"y"))
317 CreateDayList(GetCorrectComboBox(
"d"), GetCorrectComboBox(
"m").GetCurrentIndex() +1, m_aYearData.GetEntry(GetCorrectComboBox(
"y").GetCurrentIndex()));
319 UpdateDateMoonPhaseIcon();
321 OnChange(
null, 0, 0,
false);
327 super.OnMouseEnter(w, x, y);
329 GetGame().GetWorkspace().SetFocusedWidget(m_comboBox0.GetRootWidget());
333 override void HandlerDeattached(Widget w)
335 super.HandlerDeattached(w);
338 m_comboBox0.m_OnChanged.Remove(OnComboBoxChanged);
340 m_comboBox1.m_OnChanged.Remove(OnComboBoxChanged);
342 m_comboBox2.m_OnChanged.Remove(OnComboBoxChanged);