Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DateAttributeUIComponent.c
Go to the documentation of this file.
1// Script File
5{
6 [Attribute("ComboRoot")]
7 protected string m_sComboBaseName;
8
9 [Attribute(defvalue: "DateLabel")]
10 protected string m_sLabelHolderBaseName;
11
12 [Attribute(defvalue: "Label")]
13 protected string m_sLabelName;
14
15 [Attribute()]
16 protected ref array<int> m_aDayArray;
17
18 [Attribute(defvalue: "1.25")]
19 protected float m_fMonthWidgetFill;
20
24
28
31
32 protected string m_sDateOrder;
33
35
36 //---- REFACTOR NOTE START: Hardcoded numbers
37
38 override void Init(Widget w, SCR_BaseEditorAttribute attribute)
39 {
40 super.Init(w, attribute);
41
42 ChimeraWorld world = GetGame().GetWorld();
43 m_TimeAndWeatherManager = world.GetTimeAndWeatherManager();
44
46 {
47 Print("SCR_DateAttributeUIComponent could not find GetTimeAndWeatherManager!", LogLevel.ERROR);
48 return;
49 }
50
51 //Date holder
52 Widget dateHolderWidget = w.FindAnyWidget(m_sUiComponentName);
53 if (!dateHolderWidget) return;
54
55 SCR_ToolboxComponent dateHolder = SCR_ToolboxComponent.Cast(dateHolderWidget.FindHandler(SCR_ToolboxComponent));
56 if (!dateHolder) return;
57
58 //Get Labels
59 Widget labelHolder0 = w.FindAnyWidget(m_sLabelHolderBaseName + 0);
60 Widget labelHolder1 = w.FindAnyWidget(m_sLabelHolderBaseName + 1);
61 Widget labelHolder2 = w.FindAnyWidget(m_sLabelHolderBaseName + 2);
62
63 if (!labelHolder0 || !labelHolder1 || !labelHolder2) return;
64
65 m_Label0 = TextWidget.Cast(labelHolder0.FindAnyWidget(m_sLabelName));
66 m_Label1 = TextWidget.Cast(labelHolder1.FindAnyWidget(m_sLabelName));
67 m_Label2 = TextWidget.Cast(labelHolder2.FindAnyWidget(m_sLabelName));
68
69 if (!m_Label0 || !m_Label1 || !m_Label2) return;
70
71 Widget comboBoxWidget0 = w.FindAnyWidget(m_sComboBaseName + 0);
72 Widget comboBoxWidget1 = w.FindAnyWidget(m_sComboBaseName + 1);
73 Widget comboBoxWidget2 = w.FindAnyWidget(m_sComboBaseName + 2);
74
75 if (!comboBoxWidget0 || !comboBoxWidget1 || !comboBoxWidget2) return;
76
77 m_comboBox0 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget0.FindHandler(SCR_ComboBoxIconComponent));
78 m_comboBox1 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget1.FindHandler(SCR_ComboBoxIconComponent));
79 m_comboBox2 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget2.FindHandler(SCR_ComboBoxIconComponent));
80
81 if (!m_comboBox0 || !m_comboBox1 || !m_comboBox2) return;
82
83 //Set daytime presets
85 if (!var) return;
86
87 array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
88 int entriesCount = attribute.GetEntries(entries);
89 string dayLabel, monthLabel, yearLabel;
90
91 if (entriesCount > 1)
92 {
94 if (!stringData) return;
95 dateHolder.SetLabel(stringData.GetText());
96
97 stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[1]);
98 if (!stringData) return;
99 m_sDateOrder = stringData.GetText();
100
101 stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[2]);
102 if (!stringData) return;
103 dayLabel = stringData.GetText();
104
105 stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[3]);
106 if (!stringData) return;
107 monthLabel = stringData.GetText();
108
109 stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[4]);
110 if (!stringData) return;
111 yearLabel = stringData.GetText();
112
114 if (!m_aMonthData) return;
115
117 if (!m_aYearData) return;
118 }
119
122
123 vector date = var.GetVector();
124 CreateDayList(GetCorrectComboBox("d"), date[1] +1, m_aYearData.GetEntry(date[2]), false);
125
126 //Lables
127 GetCorrectLabel("d").SetText(dayLabel);
128 GetCorrectLabel("m").SetText(monthLabel);
129 GetCorrectLabel("y").SetText(yearLabel);
130
131 //Month fill weight
133
134 //Events
135 m_comboBox0.m_OnChanged.Insert(OnComboBoxChanged);
136 m_comboBox1.m_OnChanged.Insert(OnComboBoxChanged);
137 m_comboBox2.m_OnChanged.Insert(OnComboBoxChanged);
138 }
139
141 {
142 if (!var)
143 return;
144
145 vector date = var.GetVector();
146 SetDateComboBoxes(date);
147 CreateDayList(GetCorrectComboBox("d"), date[1] +1, m_aYearData.GetEntry(date[2]));
149
150 super.SetFromVar(var);
151 }
152
153 //---- REFACTOR NOTE END ----
154
155 protected void CreateDayList(SCR_ComboBoxIconComponent comboBox, int currentMonth, int currentYear, bool setMoonIcon = true)
156 {
157 int currentDateIndex = comboBox.GetCurrentIndex();
158 comboBox.ClearAll();
159 int count = m_aDayArray.Count();
160
161 if (count == 0) return;
162
163 ChimeraWorld world = GetGame().GetWorld();
164 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
165 if (!timeManager) return;
166
167 float daytime;
168 int day, month, year;
169 GetCorrectDateTime(daytime, day, month, year);
170 float timeZoneOffset = m_TimeAndWeatherManager.GetTimeZoneOffset();
171 float dstOffset = m_TimeAndWeatherManager.GetDSTOffset();
172 float latitude = m_TimeAndWeatherManager.GetCurrentLatitude();
173
174 SCR_MoonPhaseUIInfo moonPhaseInfo;
175 ResourceName preIcon;
176 ResourceName icon;
177 float rotation = 0;
178
179 if (latitude < 0)
180 rotation = 180;
181
182 for (int i = 0; i < count; i++)
183 {
184 //Check if valid date for the month and year
185 if (m_aDayArray[i] >= 29 && !timeManager.CheckValidDate(currentYear, currentMonth, m_aDayArray[i]))
186 break;
187
188 if (setMoonIcon)
189 {
190 moonPhaseInfo = m_TimeAndWeatherManager.GetMoonPhaseInfoForDate(year, month, m_aDayArray[i], daytime, timeZoneOffset, dstOffset, latitude);
191 icon = moonPhaseInfo.GetIconPath();
192
193 if (preIcon == icon)
194 icon = string.Empty;
195 else
196 preIcon = icon;
197 }
198
199 comboBox.AddItemAndIcon(m_aDayArray[i].ToString(), icon, rotation);
200 }
201
202 //Set valid date if prev date not valid
203 while (currentDateIndex >= comboBox.GetNumItems() && currentDateIndex > 0){
204 currentDateIndex--;
205 }
206
207 comboBox.SetCurrentItem(currentDateIndex);
208 }
209
210 protected void UpdateDateMoonPhaseIcon()
211 {
213 if (!m_AttributeManager.GetAttributeVariable(SCR_DaytimeEditorAttribute, dayTimeVar))
214 return;
215
216 float daytime;
217 int day, month, year;
218 GetCorrectDateTime(daytime, day, month, year);
219 float timeZoneOffset = m_TimeAndWeatherManager.GetTimeZoneOffset();
220 float dstOffset = m_TimeAndWeatherManager.GetDSTOffset();
221 float latitude = m_TimeAndWeatherManager.GetCurrentLatitude();
222
224 SCR_MoonPhaseUIInfo moonPhaseInfo = m_TimeAndWeatherManager.GetMoonPhaseInfoForDate(year, month, day, daytime, timeZoneOffset, dstOffset, latitude);
225 ImageWidget icon = dayComboBox.GetIconWidget();
226 moonPhaseInfo.SetIconTo(icon);
227 icon.SetRotation(moonPhaseInfo.GetMoonphaseImageRotation());
228 icon.SetVisible(true);
229 }
230
231 protected void GetCorrectDateTime(out float daytime, out int day, out int month, out int year)
232 {
234 if (!m_AttributeManager.GetAttributeVariable(SCR_DaytimeEditorAttribute, dayTimeVar))
235 return;
236
238 return;
239
240 daytime = dayTimeVar.GetFloat() / 3600;
241 day = GetCorrectComboBox("d").GetCurrentIndex() +1;
242 month = GetCorrectComboBox("m").GetCurrentIndex() +1;
243 year = m_aYearData.GetEntry(GetCorrectComboBox("y").GetCurrentIndex());
244 }
245
247 {
248 int count = m_aMonthData.GetCount();
249 comboBox.ClearAll();
250
251 for (int i = 0; i < count; i++)
252 {
253 comboBox.AddItem(m_aMonthData.GetEntry(i));
254 }
255 }
256
258 {
259 int count = m_aYearData.GetCount();
260 comboBox.ClearAll();
261
262 for (int i = 0; i < count; i++)
263 {
264 comboBox.AddItem(m_aYearData.GetEntry(i).ToString());
265 }
266 }
267
269 {
272 }
273
275 {
276 if (m_sDateOrder[0] == lookfor)
277 return m_comboBox0;
278 if (m_sDateOrder[1] == lookfor)
279 return m_comboBox1;
280 else
281 return m_comboBox2;
282 }
283
284 protected TextWidget GetCorrectLabel(string lookfor)
285 {
286 if (m_sDateOrder[0] == lookfor)
287 return m_Label0;
288 if (m_sDateOrder[1] == lookfor)
289 return m_Label1;
290 else
291 return m_Label2;
292 }
293
294 protected void SetDateComboBoxes(vector date)
295 {
296 GetCorrectComboBox("d").SetCurrentItem(date[0]);
297 GetCorrectComboBox("m").SetCurrentItem(date[1]);
298 GetCorrectComboBox("y").SetCurrentItem(date[2]);
299 }
300
301 override bool OnChangeInternal(Widget w, int x, int y, bool finished)
302 {
304
305 if (!attribute) return false;
306
307 SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
308
309 vector date = Vector(GetCorrectComboBox("d").GetCurrentIndex(), GetCorrectComboBox("m").GetCurrentIndex(), GetCorrectComboBox("y").GetCurrentIndex());
310 var.SetVector(date);
311
312 super.OnChangeInternal(w, x, y, finished);
313 return false;
314 }
315
316 protected void OnComboBoxChanged(SCR_ComboBoxComponent comboBox, int index)
317 {
318 //Update day
319 if (comboBox == GetCorrectComboBox("m") || comboBox == GetCorrectComboBox("y"))
320 CreateDayList(GetCorrectComboBox("d"), GetCorrectComboBox("m").GetCurrentIndex() +1, m_aYearData.GetEntry(GetCorrectComboBox("y").GetCurrentIndex()));
321
323
324 OnChangeInternal(null, 0, 0, false);
325 }
326
327 //------------------------------------------------------------------------------------------------\
328 override bool OnMouseEnter(Widget w, int x, int y)
329 {
330 super.OnMouseEnter(w, x, y);
331
332 GetGame().GetWorkspace().SetFocusedWidget(m_comboBox0.GetRootWidget());
333 return true;
334 }
335
336 override void HandlerDeattached(Widget w)
337 {
338 super.HandlerDeattached(w);
339
340 if (m_comboBox0)
341 m_comboBox0.m_OnChanged.Remove(OnComboBoxChanged);
342 if (m_comboBox1)
343 m_comboBox1.m_OnChanged.Remove(OnComboBoxChanged);
344 if (m_comboBox2)
345 m_comboBox2.m_OnChanged.Remove(OnComboBoxChanged);
346 }
347};
348
void SCR_EditorAttributeEntryStringArray(array< ref LocalizedString > values)
void SCR_BaseEditorAttributeEntryText(string text)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Faction GetParent()
Widget GetRootWidget()
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
sealed SCR_BaseEditorAttributeVar GetVariable(bool createWhenNull=false)
sealed SCR_BaseEditorAttributeVar GetVariableOrCopy()
int GetEntries(notnull array< ref SCR_BaseEditorAttributeEntry > outEntries)
Get attribute this component represents return Editor attribute *SCR_BaseEditorAttribute GetAttribute()
SCR_AttributesManagerEditorComponent m_AttributeManager
override int AddItem(string item, bool last=false, Managed data=null)
int AddItemAndIcon(string item, ResourceName icon, float rotation=0, Managed data=null)
TimeAndWeatherManagerEntity m_TimeAndWeatherManager
SCR_ComboBoxIconComponent GetCorrectComboBox(string lookfor)
GetGame().GetWorkspace().SetFocusedWidget(m_comboBox0.GetRootWidget())
void FillYearComboBox(SCR_ComboBoxIconComponent comboBox)
override void SetFromVar(SCR_BaseEditorAttributeVar var)
ref SCR_EditorAttributeEntryStringArray m_aMonthData
void OnComboBoxChanged(SCR_ComboBoxComponent comboBox, int index)
TextWidget GetCorrectLabel(string lookfor)
void GetCorrectDateTime(out float daytime, out int day, out int month, out int year)
void CreateDayList(SCR_ComboBoxIconComponent comboBox, int currentMonth, int currentYear, bool setMoonIcon=true)
void FillMonthComboBox(SCR_ComboBoxIconComponent comboBox)
override void Init(Widget w, SCR_BaseEditorAttribute attribute)
ref SCR_EditorAttributeEntryIntArray m_aYearData
override bool OnChangeInternal(Widget w, int x, int y, bool finished)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
RespawnSystemComponentClass GameComponentClass vector vector rotation
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
proto native vector Vector(float x, float y, float z)