Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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 
21  protected TextWidget m_Label0;
22  protected TextWidget m_Label1;
23  protected TextWidget m_Label2;
24 
25  protected SCR_ComboBoxIconComponent m_comboBox0;
26  protected SCR_ComboBoxIconComponent m_comboBox1;
27  protected SCR_ComboBoxIconComponent m_comboBox2;
28 
29  protected ref SCR_EditorAttributeEntryStringArray m_aMonthData;
30  protected ref SCR_EditorAttributeEntryIntArray m_aYearData;
31 
32  protected string m_sDateOrder;
33 
34  protected TimeAndWeatherManagerEntity m_TimeAndWeatherManager;
35 
36 
37  override void Init(Widget w, SCR_BaseEditorAttribute attribute)
38  {
39  super.Init(w, attribute);
40 
41  ChimeraWorld world = GetGame().GetWorld();
42  m_TimeAndWeatherManager = world.GetTimeAndWeatherManager();
43 
44  if (!m_TimeAndWeatherManager)
45  {
46  Print("SCR_DateAttributeUIComponent could not find GetTimeAndWeatherManager!", LogLevel.ERROR);
47  return;
48  }
49 
50  //Date holder
51  Widget dateHolderWidget = w.FindAnyWidget(m_sUiComponentName);
52  if (!dateHolderWidget) return;
53 
54  SCR_ToolboxComponent dateHolder = SCR_ToolboxComponent.Cast(dateHolderWidget.FindHandler(SCR_ToolboxComponent));
55  if (!dateHolder) return;
56 
57  //Get Labels
58  Widget labelHolder0 = w.FindAnyWidget(m_sLabelHolderBaseName + 0);
59  Widget labelHolder1 = w.FindAnyWidget(m_sLabelHolderBaseName + 1);
60  Widget labelHolder2 = w.FindAnyWidget(m_sLabelHolderBaseName + 2);
61 
62  if (!labelHolder0 || !labelHolder1 || !labelHolder2) return;
63 
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));
67 
68  if (!m_Label0 || !m_Label1 || !m_Label2) return;
69 
70  Widget comboBoxWidget0 = w.FindAnyWidget(m_sComboBaseName + 0);
71  Widget comboBoxWidget1 = w.FindAnyWidget(m_sComboBaseName + 1);
72  Widget comboBoxWidget2 = w.FindAnyWidget(m_sComboBaseName + 2);
73 
74  if (!comboBoxWidget0 || !comboBoxWidget1 || !comboBoxWidget2) return;
75 
76  m_comboBox0 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget0.FindHandler(SCR_ComboBoxIconComponent));
77  m_comboBox1 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget1.FindHandler(SCR_ComboBoxIconComponent));
78  m_comboBox2 = SCR_ComboBoxIconComponent.Cast(comboBoxWidget2.FindHandler(SCR_ComboBoxIconComponent));
79 
80  if (!m_comboBox0 || !m_comboBox1 || !m_comboBox2) return;
81 
82  //Set daytime presets
83  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
84  if (!var) return;
85 
86  array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
87  int entriesCount = attribute.GetEntries(entries);
88  string dayLabel, monthLabel, yearLabel;
89 
90  if (entriesCount > 1)
91  {
93  if (!stringData) return;
94  dateHolder.SetLabel(stringData.GetText());
95 
96  stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[1]);
97  if (!stringData) return;
98  m_sDateOrder = stringData.GetText();
99 
100  stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[2]);
101  if (!stringData) return;
102  dayLabel = stringData.GetText();
103 
104  stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[3]);
105  if (!stringData) return;
106  monthLabel = stringData.GetText();
107 
108  stringData = SCR_BaseEditorAttributeEntryText.Cast(entries[4]);
109  if (!stringData) return;
110  yearLabel = stringData.GetText();
111 
112  m_aMonthData = SCR_EditorAttributeEntryStringArray.Cast(entries[5]);
113  if (!m_aMonthData) return;
114 
115  m_aYearData = SCR_EditorAttributeEntryIntArray.Cast(entries[6]);
116  if (!m_aYearData) return;
117  }
118 
119  FillMonthComboBox(GetCorrectComboBox("m"));
120  FillYearComboBox(GetCorrectComboBox("y"));
121 
122  vector date = var.GetVector();
123  CreateDayList(GetCorrectComboBox("d"), date[1] +1, m_aYearData.GetEntry(date[2]), false);
124 
125  //Lables
126  GetCorrectLabel("d").SetText(dayLabel);
127  GetCorrectLabel("m").SetText(monthLabel);
128  GetCorrectLabel("y").SetText(yearLabel);
129 
130  //Month fill weight
131  SetMonthWidgetFillWeight();
132 
133  //Events
134  m_comboBox0.m_OnChanged.Insert(OnComboBoxChanged);
135  m_comboBox1.m_OnChanged.Insert(OnComboBoxChanged);
136  m_comboBox2.m_OnChanged.Insert(OnComboBoxChanged);
137  }
138 
139  override void SetFromVar(SCR_BaseEditorAttributeVar var)
140  {
141  if (!var)
142  return;
143 
144  vector date = var.GetVector();
145  SetDateComboBoxes(date);
146  CreateDayList(GetCorrectComboBox("d"), date[1] +1, m_aYearData.GetEntry(date[2]));
147  UpdateDateMoonPhaseIcon();
148 
149  super.SetFromVar(var);
150  }
151 
152  protected void CreateDayList(SCR_ComboBoxIconComponent comboBox, int currentMonth, int currentYear, bool setMoonIcon = true)
153  {
154  int currentDateIndex = comboBox.GetCurrentIndex();
155  comboBox.ClearAll();
156  int count = m_aDayArray.Count();
157 
158  if (count == 0) return;
159 
160  ChimeraWorld world = GetGame().GetWorld();
161  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
162  if (!timeManager) return;
163 
164  float daytime;
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();
170 
171  SCR_MoonPhaseUIInfo moonPhaseInfo;
172  ResourceName preIcon;
173  ResourceName icon;
174  float rotation = 0;
175 
176  if (latitude < 0)
177  rotation = 180;
178 
179  for (int i = 0; i < count; i++)
180  {
181  //Check if valid date for the month and year
182  if (m_aDayArray[i] >= 29 && !timeManager.CheckValidDate(currentYear, currentMonth, m_aDayArray[i]))
183  break;
184 
185  if (setMoonIcon)
186  {
187  moonPhaseInfo = m_TimeAndWeatherManager.GetMoonPhaseInfoForDate(year, month, m_aDayArray[i], daytime, timeZoneOffset, dstOffset, latitude);
188  icon = moonPhaseInfo.GetIconPath();
189 
190  if (preIcon == icon)
191  icon = string.Empty;
192  else
193  preIcon = icon;
194  }
195 
196  comboBox.AddItemAndIcon(m_aDayArray[i].ToString(), icon, rotation);
197  }
198 
199  //Set valid date if prev date not valid
200  while (currentDateIndex >= comboBox.GetNumItems() && currentDateIndex > 0){
201  currentDateIndex--;
202  }
203 
204  comboBox.SetCurrentItem(currentDateIndex);
205  }
206 
207  protected void UpdateDateMoonPhaseIcon()
208  {
209  SCR_BaseEditorAttributeVar dayTimeVar;
210  if (!m_AttributeManager.GetAttributeVariable(SCR_DaytimeEditorAttribute, dayTimeVar))
211  return;
212 
213  float daytime;
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();
219 
220  SCR_ComboBoxIconComponent dayComboBox = GetCorrectComboBox("d");
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);
226  }
227 
228  protected void GetCorrectDateTime(out float daytime, out int day, out int month, out int year)
229  {
230  SCR_BaseEditorAttributeVar dayTimeVar;
231  if (!m_AttributeManager.GetAttributeVariable(SCR_DaytimeEditorAttribute, dayTimeVar))
232  return;
233 
234  if (!m_comboBox0 || !m_comboBox1 || !m_comboBox2)
235  return;
236 
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());
241  }
242 
243  protected void FillMonthComboBox(SCR_ComboBoxIconComponent comboBox)
244  {
245  int count = m_aMonthData.GetCount();
246  comboBox.ClearAll();
247 
248  for (int i = 0; i < count; i++)
249  {
250  comboBox.AddItem(m_aMonthData.GetEntry(i));
251  }
252  }
253 
254  protected void FillYearComboBox(SCR_ComboBoxIconComponent comboBox)
255  {
256  int count = m_aYearData.GetCount();
257  comboBox.ClearAll();
258 
259  for (int i = 0; i < count; i++)
260  {
261  comboBox.AddItem(m_aYearData.GetEntry(i).ToString());
262  }
263  }
264 
265  protected void SetMonthWidgetFillWeight()
266  {
267  LayoutSlot.SetFillWeight((GetCorrectLabel("m").GetParent()), m_fMonthWidgetFill);
268  LayoutSlot.SetFillWeight(GetCorrectComboBox("m").GetRootWidget(), m_fMonthWidgetFill);
269  }
270 
271  protected SCR_ComboBoxIconComponent GetCorrectComboBox(string lookfor)
272  {
273  if (m_sDateOrder[0] == lookfor)
274  return m_comboBox0;
275  if (m_sDateOrder[1] == lookfor)
276  return m_comboBox1;
277  else
278  return m_comboBox2;
279  }
280 
281  protected TextWidget GetCorrectLabel(string lookfor)
282  {
283  if (m_sDateOrder[0] == lookfor)
284  return m_Label0;
285  if (m_sDateOrder[1] == lookfor)
286  return m_Label1;
287  else
288  return m_Label2;
289  }
290 
291  protected void SetDateComboBoxes(vector date)
292  {
293  GetCorrectComboBox("d").SetCurrentItem(date[0]);
294  GetCorrectComboBox("m").SetCurrentItem(date[1]);
295  GetCorrectComboBox("y").SetCurrentItem(date[2]);
296  }
297 
298  override bool OnChange(Widget w, int x, int y, bool finished)
299  {
300  SCR_BaseEditorAttribute attribute = GetAttribute();
301 
302  if (!attribute) return false;
303 
304  SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
305 
306  vector date = Vector(GetCorrectComboBox("d").GetCurrentIndex(), GetCorrectComboBox("m").GetCurrentIndex(), GetCorrectComboBox("y").GetCurrentIndex());
307  var.SetVector(date);
308 
309  super.OnChange(w, x, y, finished);
310  return false;
311  }
312 
313  protected void OnComboBoxChanged(SCR_ComboBoxComponent comboBox, int index)
314  {
315  //Update day
316  if (comboBox == GetCorrectComboBox("m") || comboBox == GetCorrectComboBox("y"))
317  CreateDayList(GetCorrectComboBox("d"), GetCorrectComboBox("m").GetCurrentIndex() +1, m_aYearData.GetEntry(GetCorrectComboBox("y").GetCurrentIndex()));
318 
319  UpdateDateMoonPhaseIcon();
320 
321  OnChange(null, 0, 0, false);
322  }
323 
324  //------------------------------------------------------------------------------------------------\
325  override bool OnMouseEnter(Widget w, int x, int y)
326  {
327  super.OnMouseEnter(w, x, y);
328 
329  GetGame().GetWorkspace().SetFocusedWidget(m_comboBox0.GetRootWidget());
330  return true;
331  }
332 
333  override void HandlerDeattached(Widget w)
334  {
335  super.HandlerDeattached(w);
336 
337  if (m_comboBox0)
338  m_comboBox0.m_OnChanged.Remove(OnComboBoxChanged);
339  if (m_comboBox1)
340  m_comboBox1.m_OnChanged.Remove(OnComboBoxChanged);
341  if (m_comboBox2)
342  m_comboBox2.m_OnChanged.Remove(OnComboBoxChanged);
343  }
344 };
345 
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_ComboBoxComponent
Definition: SCR_ComboBoxComponent.c:1
SCR_DaytimeEditorAttribute
Definition: SCR_DaytimeEditorAttribute.c:5
SCR_ComboBoxIconComponent
Definition: SCR_ComboBoxIconComponent.c:1
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
SCR_BaseEditorAttribute
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
Definition: SCR_BaseEditorAttribute.c:3
SCR_DateAttributeUIComponent
Definition: SCR_DateAttributeUIComponent.c:4
SCR_BaseEditorAttributeEntryText
void SCR_BaseEditorAttributeEntryText(string text)
Definition: SCR_BaseEditorAttribute.c:486
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_MoonPhaseUIInfo
Definition: SCR_MoonPhaseUIInfo.c:2
SCR_EditorAttributeEntryIntArray
Definition: SCR_BaseEditorAttribute.c:711
SCR_ToolboxComponent
Definition: SCR_ToolboxComponent.c:2
SCR_EditorAttributeEntryStringArray
void SCR_EditorAttributeEntryStringArray(array< ref LocalizedString > values)
Definition: SCR_BaseEditorAttribute.c:691